ok but fix todo
This commit is contained in:
parent
ccb9943abb
commit
dc72e9fd05
@ -14,9 +14,9 @@ void *run_trhead(t_philo *philo)
|
||||
{
|
||||
if (philo->all_struct->opt)
|
||||
{
|
||||
if (philo->count_eat < philo->all_struct->number_of_times_each_philosopher_must_eat)
|
||||
if (philo->count_eat == philo->all_struct->number_of_times_each_philosopher_must_eat)
|
||||
{
|
||||
return(NULL);
|
||||
exit(0); // TODO реализовать завершение программы
|
||||
}
|
||||
}
|
||||
cycle(philo);
|
||||
@ -38,8 +38,8 @@ void eating(t_philo *philo)
|
||||
{
|
||||
messages(philo->all_struct, philo, "eating");
|
||||
philo->last_eat = ft_get_time() - philo->all_struct->start_time;
|
||||
ft_msleep(philo->all_struct->time_to_eat);
|
||||
philo->count_eat++;
|
||||
my_usleep(philo->all_struct->time_to_eat);
|
||||
}
|
||||
void sleeping(t_philo *philo)
|
||||
{
|
||||
@ -48,11 +48,12 @@ void sleeping(t_philo *philo)
|
||||
messages(philo->all_struct, philo, "sleeping");
|
||||
pthread_mutex_unlock(&all->data_philo->mutex[philo->more_fork]);
|
||||
pthread_mutex_unlock(&all->data_philo->mutex[philo->less_fork]);
|
||||
my_usleep(philo->all_struct->time_to_sleep);
|
||||
ft_msleep(philo->all_struct->time_to_sleep);
|
||||
}
|
||||
|
||||
void cycle(t_philo *philo)
|
||||
{
|
||||
messages(philo->all_struct, philo, "thinking");
|
||||
take_forks(philo);
|
||||
eating(philo);
|
||||
sleeping(philo);
|
||||
@ -62,18 +63,17 @@ int run_observer(t_all *all)
|
||||
{
|
||||
int i;
|
||||
i = 0;
|
||||
time_t time;
|
||||
time_t time_eat;
|
||||
while(1)
|
||||
{
|
||||
i = 0;
|
||||
while(i <= all->number_of_philosophers)
|
||||
{
|
||||
time = (ft_get_time() - all->start_time) - all->data_philo->philors[i].last_eat;
|
||||
if (time > all->time_to_die) // TODO пофиксить смерть
|
||||
time_eat = (ft_get_time() - all->start_time) - all->data_philo->philors[i].last_eat;
|
||||
if (time_eat > all->time_to_die) // TODO пофиксить смерть
|
||||
{
|
||||
printf("%ld---------------симуляция окончена фил %d умер ---------------\n", ft_get_time() - all->start_time, i + 1);
|
||||
// ft_exit(all);
|
||||
return(0);
|
||||
return(2);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ int parse_param(t_all *all, int optional, char **argv)
|
||||
all->time_to_die = ft_atoi(argv[2]);
|
||||
all->time_to_eat = ft_atoi(argv[3]);
|
||||
all->time_to_sleep = ft_atoi(argv[4]);
|
||||
all->number_of_times_each_philosopher_must_eat = 0;
|
||||
all->opt = 0;
|
||||
return (check_param(all, 0));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user