Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo_bonus/ft_start_semaphores_bonus.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_start_semaphores_bonus.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/23 00:08:20 by yabtaour #+# #+# */
9
/* Updated: 2022/05/23 00:08:22 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers_bonus.h"
13
14
int ft_start_semaphores(t_data *data)
15
{
16
sem_unlink("philo_forks");
17
sem_unlink("philo_output");
18
sem_unlink("philo_eat");
19
data->fork = sem_open("philo_forks", O_CREAT, 0700, data->philos_num);
20
data->eat = sem_open("philo_eat", O_CREAT, 0700, 1);
21
data->output = sem_open("philo_output", O_CREAT, 0700, 1);
22
if (data->fork == SEM_FAILED
23
|| data->eat == SEM_FAILED || data->output == SEM_FAILED)
24
{
25
ft_destroy_sem(data);
26
free(data);
27
exit (1);
28
}
29
return (1);
30
}
31
32