aboutsummaryrefslogtreecommitdiff
path: root/philo_one/src/event.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-04 12:20:25 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-04 12:20:25 +0100
commit907debbb7d1e7ccc4914805cfe4acbed92b82bcc (patch)
tree199d60e60d9d9b689062c5f08d6381c090127619 /philo_one/src/event.c
parent7e971b3fa805c40d02ac3e996ab1d181f9584866 (diff)
downloadphilosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.tar.gz
philosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.tar.bz2
philosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.zip
Added buffered output, Added waiting for all to be started
Diffstat (limited to 'philo_one/src/event.c')
-rw-r--r--philo_one/src/event.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/philo_one/src/event.c b/philo_one/src/event.c
index 8ceab65..2e24772 100644
--- a/philo_one/src/event.c
+++ b/philo_one/src/event.c
@@ -6,21 +6,25 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */
-/* Updated: 2021/01/03 16:48:00 by cacharle ### ########.fr */
+/* Updated: 2021/01/04 12:08:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo_one.h"
-void event_take_fork(t_philo *arg, pthread_mutex_t *fork)
+void event_take_fork(t_philo *arg)
{
if (philo_finished(arg->conf))
return ;
- pthread_mutex_lock(fork);
+ pthread_mutex_lock(arg->fork_left);
+ pthread_mutex_lock(arg->fork_right);
pthread_mutex_lock(&arg->conf->mutex_stdout);
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_FORK, arg->conf->initial_time);
+ if (philo_finished(arg->conf))
+ return ;
+ philo_put(arg->id, EVENT_FORK, arg->conf->initial_time);
pthread_mutex_unlock(&arg->conf->mutex_stdout);
}
@@ -32,6 +36,8 @@ void event_eat(t_philo *arg)
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_EAT, arg->conf->initial_time);
+ if (arg->conf->philo_num < 30)
+ philo_put_flush();
pthread_mutex_unlock(&arg->conf->mutex_stdout);
h_sleep(arg->conf->timeout_eat);
}
@@ -69,9 +75,6 @@ void event_die(t_philo *arg)
if (philo_finished(arg->conf))
return ;
pthread_mutex_lock(&arg->conf->mutex_stdout);
- if (philo_finished(arg->conf))
- return ;
- arg->conf->all_alive = false;
philo_put(arg->id, EVENT_DIE, arg->conf->initial_time);
- pthread_mutex_unlock(&arg->conf->mutex_stdout);
+ arg->conf->all_alive = false;
}