aboutsummaryrefslogtreecommitdiff
path: root/philo_one/routine.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-15 01:47:26 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-15 01:47:26 +0100
commit2c5abe421b7a1b92081e38f6b1f04d407fcba834 (patch)
treec7e7aa9db3a3b84bd80bc8a5a713d5bfeb6a66f7 /philo_one/routine.c
parent6a1e91750ee43fccb6160af0f44139698c8dfdc3 (diff)
downloadphilosophers-2c5abe421b7a1b92081e38f6b1f04d407fcba834.tar.gz
philosophers-2c5abe421b7a1b92081e38f6b1f04d407fcba834.tar.bz2
philosophers-2c5abe421b7a1b92081e38f6b1f04d407fcba834.zip
philo_one small refactoring, philo_three draft
Diffstat (limited to 'philo_one/routine.c')
-rw-r--r--philo_one/routine.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/philo_one/routine.c b/philo_one/routine.c
index 7954174..89fe95e 100644
--- a/philo_one/routine.c
+++ b/philo_one/routine.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 01:11:27 by cacharle #+# #+# */
-/* Updated: 2020/02/14 21:43:37 by cacharle ### ########.fr */
+/* Updated: 2020/02/15 01:25:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,16 +25,15 @@ void *routine_philo(void *void_arg)
return (NULL);
io_think(arg);
while (arg->args->all_alive)
- if (!arg->fork_left->used && !arg->fork_right->used)
- {
- fork_switch(arg->fork_left);
- fork_switch(arg->fork_right);
- io_eat(arg);
- fork_switch(arg->fork_left);
- fork_switch(arg->fork_right);
- io_sleep(arg);
- io_think(arg);
- }
+ {
+ pthread_mutex_lock(arg->fork_left);
+ pthread_mutex_lock(arg->fork_right);
+ io_eat(arg);
+ pthread_mutex_unlock(arg->fork_right);
+ pthread_mutex_unlock(arg->fork_left);
+ io_sleep(arg);
+ io_think(arg);
+ }
pthread_join(thread_death, NULL);
return (NULL);
}