prepare for ilja fix
This commit is contained in:
parent
8346d011dd
commit
f503236a75
@ -56,7 +56,6 @@ int runner(t_all *all, int optional);
|
|||||||
int return_big(int a, int b);
|
int return_big(int a, int b);
|
||||||
int return_less(int a, int b);
|
int return_less(int a, int b);
|
||||||
time_t ft_get_time(void);
|
time_t ft_get_time(void);
|
||||||
unsigned long ft_time_is(void);
|
|
||||||
void *run_trhead(t_philo *philo);
|
void *run_trhead(t_philo *philo);
|
||||||
int prepare_resources(t_all *all);
|
int prepare_resources(t_all *all);
|
||||||
int check_all_run(t_all *all);
|
int check_all_run(t_all *all);
|
||||||
|
|||||||
@ -32,11 +32,13 @@ void take_forks(t_philo *philo)
|
|||||||
void eating(t_philo *philo)
|
void eating(t_philo *philo)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&philo->eat_mutex);
|
pthread_mutex_lock(&philo->eat_mutex);
|
||||||
|
philo->is_eat = 1;
|
||||||
philo->last_eat = ft_get_time();
|
philo->last_eat = ft_get_time();
|
||||||
philo->limit = philo->last_eat + philo->all_struct->time_to_die;
|
philo->limit = philo->last_eat + philo->all_struct->time_to_die;
|
||||||
messages(philo->all_struct, philo, "eating");
|
messages(philo->all_struct, philo, "eating");
|
||||||
usleep(philo->all_struct->time_to_eat * 1000);
|
usleep(philo->all_struct->time_to_eat * 1000);
|
||||||
philo->count_eat++;
|
philo->count_eat++;
|
||||||
|
philo->is_eat = 0;
|
||||||
pthread_mutex_unlock(&philo->eat_mutex);
|
pthread_mutex_unlock(&philo->eat_mutex);
|
||||||
}
|
}
|
||||||
void sleeping(t_philo *philo)
|
void sleeping(t_philo *philo)
|
||||||
@ -62,40 +64,22 @@ void cycle(t_philo *philo)
|
|||||||
int run_observer(t_all *all)
|
int run_observer(t_all *all)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int died;
|
|
||||||
time_t time;
|
time_t time;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
died = 0;
|
|
||||||
time = ft_get_time();
|
time = ft_get_time();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
while(i <= all->number_of_philosophers)
|
while(i <= all->number_of_philosophers)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!all->data_philo->philors[i].is_eat && ft_get_time() > all->data_philo->philors[i].limit)
|
if (!all->data_philo->philors[i].is_eat && ft_get_time() > all->data_philo->philors[i].limit)
|
||||||
{
|
{
|
||||||
// TODO пофиксить смерть
|
// TODO пофиксить смерть
|
||||||
printf("симуляция окончена фил умер\n");
|
|
||||||
|
printf("симуляция окончена фил %d умер\n", i + 1);
|
||||||
exit(0);
|
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);
|
return (0);
|
||||||
|
|||||||
@ -96,13 +96,3 @@ time_t ft_get_time(void)
|
|||||||
return (return_value);
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user