-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_2_threads_routine.c
42 lines (39 loc) · 1.56 KB
/
3_2_threads_routine.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
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 3_2_threads_routine.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anhigo-s <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/23 00:08:16 by anhigo-s #+# #+# */
/* Updated: 2022/03/29 13:31:16 by anhigo-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
void *main_routine(void *ptr)
{
t_thinker *list;
list = (t_thinker *)ptr;
list->time_start = timenow();
list->last_meal = list->time_start;
if (list->index % 2 == 0)
waiting(list->data->args.time_eat);
while (list->data->philo_alive == true)
{
if (list->data->args.nbr_philo == 1)
{
pthread_mutex_lock(&list->fork);
pthread_mutex_lock(&list->data->printer_mutex);
printf("%zu\t%s %d\n", \
(timenow() - list->time_start), FORK, list->index);
pthread_mutex_unlock(&list->data->printer_mutex);
waiting(list->data->args.time_die);
}
fork_lock(list);
lunchtime(list);
fork_unlock(list);
naptime(list);
thinker(list);
}
return (NULL);
}