-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_check.c
37 lines (34 loc) · 1.37 KB
/
thread_check.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* thread_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gichlee <gichlee@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 17:59:50 by gichlee #+# #+# */
/* Updated: 2023/08/04 13:50:22 by gichlee ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
void count_eating(t_phil *p)
{
p->count_eat++;
pthread_mutex_lock(&p->s->m_finished_phil);
if (p->s->is_limit && p->count_eat == p->s->num_must_eat)
{
p->s->finished_phil++;
pthread_mutex_unlock(&p->s->m_finished_phil);
}
pthread_mutex_unlock(&p->s->m_finished_phil);
}
int check_dead(t_phil *p)
{
pthread_mutex_lock(&p->s->m_dead);
if (p->s->is_dead == TRUE)
{
pthread_mutex_unlock(&p->s->m_dead);
return (TRUE);
}
pthread_mutex_unlock(&p->s->m_dead);
return (FALSE);
}