diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 10:43:43 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 10:43:43 +0200 |
| commit | f0a36076950bf0c3356ad73382ce3d341cdb0463 (patch) | |
| tree | 5678bcfa57c94abb918b3d53b8e3ccd28a9c770a /philo_one/io.c | |
| parent | 3c2c3a07396c001f51eac8d0fd0fc84e83eb127b (diff) | |
| download | philosophers-f0a36076950bf0c3356ad73382ce3d341cdb0463.tar.gz philosophers-f0a36076950bf0c3356ad73382ce3d341cdb0463.tar.bz2 philosophers-f0a36076950bf0c3356ad73382ce3d341cdb0463.zip | |
Added multiple meal, Removing bloat
Diffstat (limited to 'philo_one/io.c')
| -rw-r--r-- | philo_one/io.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/philo_one/io.c b/philo_one/io.c index b4d9949..c91e9ab 100644 --- a/philo_one/io.c +++ b/philo_one/io.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2020/04/22 13:37:40 by charles ### ########.fr */ +/* Updated: 2020/09/27 10:33:29 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,12 +31,19 @@ static void philo_put(int id, t_philo_event event) void io_eat(t_routine_arg *arg) { - if (!arg->conf->all_alive) - return ; - pthread_mutex_lock(&arg->conf->mutex_stdout); - philo_put(arg->philo->id, EVENT_EAT); - pthread_mutex_unlock(&arg->conf->mutex_stdout); - usleep(arg->conf->timeout_eat * 1000); + int eat_counter; + + eat_counter = 0; + while (eat_counter < arg->conf->meal_num) + { + if (!arg->conf->all_alive) + return ; + pthread_mutex_lock(&arg->conf->mutex_stdout); + philo_put(arg->philo->id, EVENT_EAT); + pthread_mutex_unlock(&arg->conf->mutex_stdout); + usleep(arg->conf->timeout_eat * 1000); + eat_counter++; + } } void io_think(t_routine_arg *arg) |
