-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_utils.c
53 lines (47 loc) · 1.9 KB
/
thread_utils.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
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* thread_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wlalaoui <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 13:36:15 by wlalaoui #+# #+# */
/* Updated: 2024/01/12 15:56:25 by wlalaoui ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
void printf_sleep(t_philo *data)
{
pthread_mutex_lock(&data->args->printf_mutex);
printf("%ld %ld is sleeping\n",
cur_t() - data->args->b_t, data->i);
pthread_mutex_unlock(&data->args->printf_mutex);
}
void printf_eat(t_philo *data)
{
pthread_mutex_lock(&data->args->printf_mutex);
printf("%ld %ld is eating\n",
cur_t() - data->args->b_t, data->i);
pthread_mutex_unlock(&data->args->printf_mutex);
}
void printf_fork(t_philo *data)
{
pthread_mutex_lock(&data->args->printf_mutex);
printf("%ld %ld has taken a fork\n",
cur_t() - data->args->b_t, data->i);
pthread_mutex_unlock(&data->args->printf_mutex);
}
void printf_think(t_philo *data)
{
pthread_mutex_lock(&data->args->printf_mutex);
printf("%ld %ld is thinking\n",
cur_t() - data->args->b_t, data->i);
pthread_mutex_unlock(&data->args->printf_mutex);
}
void printf_die(t_data *d, size_t i)
{
pthread_mutex_lock(&d->args.printf_mutex);
printf("%ld %ld died\n",
cur_t() - d->args.b_t, d->ph_l[i].i);
pthread_mutex_unlock(&d->args.printf_mutex);
}