prepare for ilja fix

This commit is contained in:
Matthos Denys 2021-05-15 13:52:02 +03:00
parent 8346d011dd
commit f503236a75
3 changed files with 5 additions and 32 deletions

View File

@ -56,7 +56,6 @@ int runner(t_all *all, int optional);
int return_big(int a, int b);
int return_less(int a, int b);
time_t ft_get_time(void);
unsigned long ft_time_is(void);
void *run_trhead(t_philo *philo);
int prepare_resources(t_all *all);
int check_all_run(t_all *all);

View File

@ -32,11 +32,13 @@ void take_forks(t_philo *philo)
void eating(t_philo *philo)
{
pthread_mutex_lock(&philo->eat_mutex);
philo->is_eat = 1;
philo->last_eat = ft_get_time();
philo->limit = philo->last_eat + philo->all_struct->time_to_die;
messages(philo->all_struct, philo, "eating");
usleep(philo->all_struct->time_to_eat * 1000);
philo->count_eat++;
philo->is_eat = 0;
pthread_mutex_unlock(&philo->eat_mutex);
}
void sleeping(t_philo *philo)
@ -62,40 +64,22 @@ void cycle(t_philo *philo)
int run_observer(t_all *all)
{
int i;
int died;
time_t time;
i = 0;
died = 0;
time = ft_get_time();
while(1)
{
i = 0;
while(i <= all->number_of_philosophers)
{
if (!all->data_philo->philors[i].is_eat && ft_get_time() > all->data_philo->philors[i].limit)
{
// TODO пофиксить смерть
printf("симуляция окончена фил умер\n");
printf("симуляция окончена фил %d умер\n", i + 1);
exit(0);
}
if (all->data_philo->philors[i].died == 0)
{
time = ft_get_time();
i++;
}
else
{
died = 42;
break;
}
}
if (died == 42)
{
printf("симуляция окончена фил умер\n");
break;
}
}
return (0);

View File

@ -96,13 +96,3 @@ time_t ft_get_time(void)
return (return_value);
}
unsigned long ft_time_is(void)
{
static struct timeval tv;
gettimeofday(&tv, NULL);
return ((tv.tv_sec * (unsigned long)1000) + (tv.tv_usec / 1000));
}