create messages and fix qulvo phil
This commit is contained in:
parent
bc188d8c05
commit
66c8025548
@ -17,6 +17,7 @@ typedef struct s_philo
|
||||
int count_eat;
|
||||
time_t time_to_die;
|
||||
int died;
|
||||
int nbr_philo;
|
||||
pthread_mutex_t *eat_mutex;
|
||||
} t_philo;
|
||||
|
||||
@ -35,6 +36,7 @@ typedef struct s_all
|
||||
int number_of_times_each_philosopher_must_eat;
|
||||
time_t start_time;
|
||||
t_philo_data *data_philo;
|
||||
pthread_mutex_t write;
|
||||
} t_all;
|
||||
|
||||
void *ft_calloc(size_t num, size_t size);
|
||||
|
||||
@ -53,6 +53,7 @@ void get_fork_for_philo(t_all *all)
|
||||
all->data_philo->philors[i].less_fork = return_less(i, i + 1);
|
||||
}
|
||||
all->data_philo->philors[i].died = 0;
|
||||
all->data_philo->philors[i].nbr_philo = i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -104,6 +105,25 @@ void run_all_phils(t_all *all)
|
||||
}
|
||||
}
|
||||
|
||||
void philo_think(t_all *all, int i)
|
||||
{
|
||||
time_t time;
|
||||
|
||||
pthread_mutex_lock(&all->data_philo->mutex[all->data_philo->philors[i].less_fork]);
|
||||
pthread_mutex_lock(&all->data_philo->mutex[all->data_philo->philors[i].more_fork]);
|
||||
time = ft_get_time();
|
||||
time = ft_get_time();
|
||||
}
|
||||
|
||||
|
||||
void messages(t_all *all, time_t *time, int phil, char *str)
|
||||
{
|
||||
pthread_mutex_lock(&all->write);
|
||||
phil++;
|
||||
printf("%lu %d %s\n", (unsigned long)time, phil, str);
|
||||
pthread_mutex_unlock(&all->write);
|
||||
}
|
||||
|
||||
int run_observer(t_all *all)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -33,7 +33,7 @@ int parse_param(t_all *all, int optional, char **argv)
|
||||
{
|
||||
if (optional)
|
||||
{
|
||||
all->number_of_philosophers = ft_atoi(argv[1]);
|
||||
all->number_of_philosophers = ft_atoi(argv[1]) - 1;
|
||||
all->time_to_die = ft_atoi(argv[2]);
|
||||
all->time_to_eat = ft_atoi(argv[3]);
|
||||
all->time_to_sleep = ft_atoi(argv[4]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user