-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.c
37 lines (34 loc) · 785 Bytes
/
checks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "philo.h"
int ft_dead_check(t_philo *philo)
{
int j;
pthread_mutex_lock(&philo->datas->dead);
j = 0;
while (j < philo->datas->total_philos)
{
if (philo[j].is_dead == 1)
{
printf("%lld %d is dead.\n", \
get_tick_count() - philo->datas->start_time, philo[j].who);
return (j);
}
j++;
}
pthread_mutex_unlock(&philo->datas->dead);
return (-1);
}
int check(t_philo *philo)
{
pthread_mutex_lock(&philo->datas->dead);
if (get_tick_count() >= philo->datas->time_to_die + philo->last_eat)
{
philo->datas->is_dead = 1;
philo->is_dead = 1;
pthread_mutex_unlock(&philo->datas->dead);
pthread_mutex_lock(&philo->datas->pprint);
return (0);
}
pthread_mutex_unlock(&philo->datas->m_stop);
pthread_mutex_unlock(&philo->datas->dead);
return (0);
}