diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-03 16:58:00 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-03 16:58:00 +0100 |
| commit | 7e971b3fa805c40d02ac3e996ab1d181f9584866 (patch) | |
| tree | f904b6f96e0080b86aadd4d9047f7dfb855c3a3d /philo_one | |
| parent | e874ad94a31a8259b8eb7ad2865767c081bcd279 (diff) | |
| download | philosophers-7e971b3fa805c40d02ac3e996ab1d181f9584866.tar.gz philosophers-7e971b3fa805c40d02ac3e996ab1d181f9584866.tar.bz2 philosophers-7e971b3fa805c40d02ac3e996ab1d181f9584866.zip | |
Added h_sleep instead of usleep for better precision
Diffstat (limited to 'philo_one')
| -rw-r--r-- | philo_one/src/event.c | 6 | ||||
| -rw-r--r-- | philo_one/src/philo.c | 2 | ||||
| -rw-r--r-- | philo_one/src/routine.c | 12 |
3 files changed, 7 insertions, 13 deletions
diff --git a/philo_one/src/event.c b/philo_one/src/event.c index 4abfa67..8ceab65 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/03 13:56:42 by cacharle ### ########.fr */ +/* Updated: 2021/01/03 16:48:00 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ void event_eat(t_philo *arg) return ; philo_put(arg->id, EVENT_EAT, arg->conf->initial_time); pthread_mutex_unlock(&arg->conf->mutex_stdout); - usleep(arg->conf->timeout_eat * 1000); + h_sleep(arg->conf->timeout_eat); } void event_think(t_philo *arg) @@ -61,7 +61,7 @@ void event_sleep( pthread_mutex_unlock(&arg->conf->mutex_stdout); pthread_mutex_unlock(fork_right); pthread_mutex_unlock(fork_left); - usleep(arg->conf->timeout_sleep * 1000); + h_sleep(arg->conf->timeout_sleep); } void event_die(t_philo *arg) diff --git a/philo_one/src/philo.c b/philo_one/src/philo.c index 1ffb15b..870857b 100644 --- a/philo_one/src/philo.c +++ b/philo_one/src/philo.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/09 23:47:14 by cacharle #+# #+# */ -/* Updated: 2021/01/01 13:33:47 by charles ### ########.fr */ +/* Updated: 2021/01/03 16:49:45 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/philo_one/src/routine.c b/philo_one/src/routine.c index 70e6694..d8291ef 100644 --- a/philo_one/src/routine.c +++ b/philo_one/src/routine.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 01:11:27 by cacharle #+# #+# */ -/* Updated: 2021/01/03 12:23:35 by cacharle ### ########.fr */ +/* Updated: 2021/01/03 16:42:36 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,15 +59,9 @@ void *routine_philo(t_philo *arg) void *routine_death(t_philo *arg) { - t_time current; - - current = h_time_now(); while (!philo_finished(arg->conf) && - current - arg->time_last_eat < arg->conf->timeout_death) - { - current = h_time_now(); - usleep(1000); - } + h_time_now() - arg->time_last_eat < arg->conf->timeout_death) + usleep(500); event_die(arg); return (NULL); } |
