diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-10 10:54:04 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-10 10:54:04 +0100 |
| commit | eb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb (patch) | |
| tree | efff80bbbc2157979eaae006f6835d020062dba9 /philo_one/src/event.c | |
| parent | 802ea8347d1ceb7a02cf279359b3b101106fab94 (diff) | |
| download | philosophers-eb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb.tar.gz philosophers-eb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb.tar.bz2 philosophers-eb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb.zip | |
Fixing bad performance at school by adding more delay to the death checking loop, Added mutex/semaphore to protect against eating and dying at the same time
Diffstat (limited to 'philo_one/src/event.c')
| -rw-r--r-- | philo_one/src/event.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/philo_one/src/event.c b/philo_one/src/event.c index 92ca399..88b9ff1 100644 --- a/philo_one/src/event.c +++ b/philo_one/src/event.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2021/01/09 13:12:20 by charles ### ########.fr */ +/* Updated: 2021/01/10 09:55:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,14 +28,15 @@ void event_eat(t_philo *arg) { if (philo_finished(arg->conf)) return ; + pthread_mutex_lock(&arg->mutex_eat); pthread_mutex_lock(&arg->conf->mutex_stdout); if (philo_finished(arg->conf)) return ; philo_put(arg->id, EVENT_EAT, arg->conf->initial_time); pthread_mutex_unlock(&arg->conf->mutex_stdout); arg->time_last_eat = h_time_now(); + pthread_mutex_unlock(&arg->mutex_eat); h_sleep(arg->conf->timeout_eat); - arg->time_last_eat = h_time_now(); } void event_think(t_philo *arg) |
