-int *id; /* to pass a pointer to the threads without race condition */
-
-static void pickup(int id, int lunch) {
- INFO2("Thread %d gets hungry (lunch #%d)",id,lunch);
- xbt_mutex_lock(mutex);
- while (state[(id + (philosopher_amount-1))%philosopher_amount] == EATING ||
- state[(id + 1)%philosopher_amount] == EATING)
- {
- xbt_cond_wait(forks[id], mutex);
- }
-
- state[id] = EATING;
- xbt_assert1(state[(id + (philosopher_amount-1))%philosopher_amount] == THINKING &&
- state[(id + 1)%philosopher_amount] == THINKING ,
- "Philosopher %d eats at the same time that one of its neighbors!!!",id);
-
- xbt_mutex_unlock(mutex);
- INFO1("Thread %d eats",id);
+int *id; /* to pass a pointer to the threads without race condition */
+
+static void pickup(int id, int lunch)
+{
+ INFO2("Thread %d gets hungry (lunch #%d)", id, lunch);
+ xbt_mutex_acquire(mutex);
+ while (state[(id + (philosopher_amount - 1)) % philosopher_amount] == EATING
+ || state[(id + 1) % philosopher_amount] == EATING) {
+ xbt_cond_wait(forks[id], mutex);
+ }
+
+ state[id] = EATING;
+ xbt_assert1(state[(id + (philosopher_amount - 1)) % philosopher_amount] ==
+ THINKING
+ && state[(id + 1) % philosopher_amount] == THINKING,
+ "Philosopher %d eats at the same time that one of its neighbors!!!",
+ id);
+
+ xbt_mutex_release(mutex);
+ INFO1("Thread %d eats", id);