|
|
@ -6,13 +6,13 @@ |
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/16 14:03:42 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/20 09:57:34 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/20 10:34:10 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
#include "philo.h" |
|
|
|
|
|
|
|
void *check_halt(void * p) |
|
|
|
void *check_halt(void *p) |
|
|
|
{ |
|
|
|
int time; |
|
|
|
t_philo *philo; |
|
|
@ -63,7 +63,6 @@ void init_philos(t_table *table) |
|
|
|
|
|
|
|
amount = table->param[PHILO_AMOUNT]; |
|
|
|
table->pid = malloc(sizeof(pid_t) * amount); |
|
|
|
//memset(table->pid, 0, sizeof(pid_t) * amount);
|
|
|
|
i = 0; |
|
|
|
while (i < amount) |
|
|
|
{ |
|
|
@ -81,18 +80,19 @@ void init_philos(t_table *table) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|
int main(int argc, char **argv) |
|
|
|
{ |
|
|
|
static t_table *table; |
|
|
|
static int i = 0; |
|
|
|
int status; |
|
|
|
static int i = 0; |
|
|
|
static int status; |
|
|
|
|
|
|
|
sem_unlink("/chopsticks"); |
|
|
|
sem_unlink("/death"); |
|
|
|
if (argc < 5 || argc > 6) |
|
|
|
return (1); |
|
|
|
table = parsing(argv + 1); |
|
|
|
table->sptr = sem_open("/chopsticks", O_CREAT, 0664, table->param[PHILO_AMOUNT]); |
|
|
|
table->sptr = sem_open("/chopsticks", O_CREAT, 0664, |
|
|
|
table->param[PHILO_AMOUNT]); |
|
|
|
table->death = sem_open("/death", O_CREAT, 0664, 1); |
|
|
|
init_philos(table); |
|
|
|
waitpid(-1, &status, 0); |
|
|
@ -103,5 +103,5 @@ int main(int argc, char **argv) |
|
|
|
} |
|
|
|
sem_unlink("/chopsticks"); |
|
|
|
sem_unlink("/deaths"); |
|
|
|
return(0); |
|
|
|
return (0); |
|
|
|
} |
|
|
|