|
@ -6,7 +6,7 @@ |
|
|
/* By: narnaud@student.42nice.fr <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
/* By: narnaud@student.42nice.fr <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
/* Created: 2022/05/19 00:36:57 by narnaud@stude #+# #+# */ |
|
|
/* Created: 2022/05/19 00:36:57 by narnaud@stude #+# #+# */ |
|
|
/* Updated: 2022/05/19 00:47:15 by narnaud@stude ### ########.fr */ |
|
|
/* Updated: 2022/05/19 01:41:03 by narnaud ### ########.fr */ |
|
|
/* */ |
|
|
/* */ |
|
|
/* ************************************************************************** */ |
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ int main(int argc, char **argv) |
|
|
pthread_mutex_lock(room->lock); |
|
|
pthread_mutex_lock(room->lock); |
|
|
room->running = 0; |
|
|
room->running = 0; |
|
|
pthread_mutex_unlock(room->lock); |
|
|
pthread_mutex_unlock(room->lock); |
|
|
sleep(2); |
|
|
sleep(1); |
|
|
return (clean_memory(room, philos)); |
|
|
return (clean_memory(room, philos)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -45,9 +45,9 @@ static int waiter(t_room *room, t_philo *philo) |
|
|
while (ret && philo->id >= 0) |
|
|
while (ret && philo->id >= 0) |
|
|
{ |
|
|
{ |
|
|
pthread_mutex_lock(philo->lock); |
|
|
pthread_mutex_lock(philo->lock); |
|
|
if (philo->eat_time + room->param[DIE_TIME] < room_clock()) |
|
|
if ((philo->eat_time + room->param[DIE_TIME]) < room_clock()) |
|
|
{ |
|
|
{ |
|
|
safe_print(philo, "%d %d died\n"); |
|
|
printf("%d %d died\n", room_clock(), philo->id); |
|
|
ret = 0; |
|
|
ret = 0; |
|
|
} |
|
|
} |
|
|
if (philo->eat_amount < starvest) |
|
|
if (philo->eat_amount < starvest) |
|
@ -65,7 +65,6 @@ static int clean_memory(t_room *room, t_philo *philos) |
|
|
{ |
|
|
{ |
|
|
static int i = 0; |
|
|
static int i = 0; |
|
|
|
|
|
|
|
|
pthread_mutex_lock(room->lock); |
|
|
|
|
|
while (i < room->param[PHILO_AMOUNT]) |
|
|
while (i < room->param[PHILO_AMOUNT]) |
|
|
{ |
|
|
{ |
|
|
pthread_mutex_lock(philos[i].lock); |
|
|
pthread_mutex_lock(philos[i].lock); |
|
@ -78,7 +77,6 @@ static int clean_memory(t_room *room, t_philo *philos) |
|
|
free(philos[i].thd); |
|
|
free(philos[i].thd); |
|
|
i++; |
|
|
i++; |
|
|
} |
|
|
} |
|
|
pthread_mutex_unlock(room->lock); |
|
|
|
|
|
pthread_mutex_destroy(room->lock); |
|
|
pthread_mutex_destroy(room->lock); |
|
|
free(room->lock); |
|
|
free(room->lock); |
|
|
free(room->forks); |
|
|
free(room->forks); |
|
|