Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo/ft_start_mutex.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_start_mutex.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/19 22:14:47 by yabtaour #+# #+# */
9
/* Updated: 2022/05/19 22:14:49 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers.h"
13
14
int ft_start_mutex(t_data *data)
15
{
16
int i;
17
18
i = 0;
19
while (i < data->philos_num)
20
{
21
if (pthread_mutex_init(&data->fork[i], NULL) != 0)
22
{
23
free(data);
24
return (0);
25
}
26
i++;
27
}
28
if (pthread_mutex_init(&data->output, NULL) != 0)
29
{
30
free(data);
31
return (0);
32
}
33
if (pthread_mutex_init(&data->eat, NULL) != 0)
34
{
35
free(data);
36
return (0);
37
}
38
return (1);
39
}
40
41