|
@ -6,7 +6,7 @@ |
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
/* Created: 2021/11/24 15:44:04 by narnaud #+# #+# */ |
|
|
/* Created: 2021/11/24 15:44:04 by narnaud #+# #+# */ |
|
|
/* Updated: 2022/05/19 22:24:51 by narnaud@stude ### ########.fr */ |
|
|
/* Updated: 2022/05/20 08:38:02 by narnaud ### ########.fr */ |
|
|
/* */ |
|
|
/* */ |
|
|
/* ************************************************************************** */ |
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
@ -37,12 +37,15 @@ t_philo *create_philos(t_room *room) |
|
|
{ |
|
|
{ |
|
|
t_philo *ret; |
|
|
t_philo *ret; |
|
|
static int i; |
|
|
static int i; |
|
|
|
|
|
int amount; |
|
|
|
|
|
|
|
|
ret = (t_philo *)malloc((room->param[PHILO_AMOUNT] + 1) * sizeof(t_philo)); |
|
|
amount = room->param[PHILO_AMOUNT]; |
|
|
while (i < room->param[PHILO_AMOUNT]) |
|
|
ret = (t_philo *)malloc((amount + 1) * sizeof(t_philo)); |
|
|
|
|
|
while (i < amount) |
|
|
{ |
|
|
{ |
|
|
ret[i].fork = &room->forks[i]; |
|
|
ret[i].fork = &room->forks[i]; |
|
|
ret[i].fork_r = &room->forks[(i + 1) % room->param[PHILO_AMOUNT]]; |
|
|
if (amount > 1) |
|
|
|
|
|
ret[i].fork_r = &room->forks[(i + 1) % amount]; |
|
|
ret[i].lock = malloc(sizeof(pthread_mutex_t)); |
|
|
ret[i].lock = malloc(sizeof(pthread_mutex_t)); |
|
|
ret[i].thd = malloc(sizeof(pthread_t)); |
|
|
ret[i].thd = malloc(sizeof(pthread_t)); |
|
|
ret[i].room = room; |
|
|
ret[i].room = room; |
|
@ -77,6 +80,6 @@ void invit_philos(t_philo *philos) |
|
|
else if ((i % 2) == 1) |
|
|
else if ((i % 2) == 1) |
|
|
i -= 2; |
|
|
i -= 2; |
|
|
philo = philos + i; |
|
|
philo = philos + i; |
|
|
usleep(10); |
|
|
usleep(50); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|