Due Oct. 21 (a week and a day) Suppose we have four dining philosophers at a round table. There is one chopstick between each pair of philosophers. A philosopher needs to pick up a chopstick from the left and a chopstick from the right in order to eat (dine). If each philospher first picks up the chipstick on their left, then no philosopher can eat, since no philosopher can pick up a chopstick on their right. Our solution will be to guarantee that at least one philosopher can eat. As before, assume four philosophers. In the main() routine, call pthread_create() to create five philosophers. The start function should be called philosopher(int *i), where i varies from 0 to 3. Also, create a semaphore whose count is initialized to 3. Conceptually, we have a global array for the state of the chopsticks (which you may or may not need): int chopstick[4] = {0,0,0,0}; Finally, create an array of mutexes: pthread_mutex_t mutex[4]; Inside main(), initialize: mutex[i] = PTHREAD_MUTEX_INITIALIZER; for each i as i goes from 0 to 3. Inside the function philosopher(), each philosopher should set a local variable, "int x;", based on the argument i that it received. It should then call: sem_wait() [ on the semaphore ] followed by: sleep( random() % 5 ); pthread_mutex_lock( mutex[ (x+4-1) % 4 ]; // left chopstick held followed by: sleep( random() % 5 ); followed by: pthread_mutex_lock( mutex[ (x+4+1) % 4 ]; // right chopstick held printf("Diner %d is eating: %d\n", i); followed by: sleep( random() % 5 ); pthread_mutex_unlock( mutex[ (x+4-1) % 4 ] ); // left chopstick released pthread_mutex_unlock( mutex[ (x+4+1) % 4 ] ); // right chopstick released sem_post() [ on the semaphore ] Then compile and run the code several times. You should always see at least one dining philospher eating. Next, change the initial value of the semaphore to 4 instead of 3. Try running the code several times. You should now see an occasional deadlock (in which no philosphoer is eating).