Dining Philosopher


Dining Table
  • Philosopher #1
  • Philosopher #2
  • Philosopher #3
  • Philosopher #4
  • Philosopher #5
Eating Philosopher
State
  • Chopstick #1
  • Chopstick #2
  • Chopstick #3
  • Chopstick #4
  • Chopstick #5
What's going on?
Dining-Philosopher
void *thinkEatRepeat() {
Thinking...

pthread_mutex_lock(&chopsticks[i]);
pthread_mutex_lock(&chopsticks[(i+1)%n]);

Eating...

pthread_mutex_unlock(&chopsticks[i]);
pthread_mutex_unlock(&chopsticks[(i+1)%n]);   

Finished Eating...

}
Dining Philosopher