CS3500 Lab 5: Thread Synchronization solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

1. Dining Philosopher Problem

The task is to implement the classic synchronization – Dining philosopher problem.

Introduction Say there are N (the value of N will be given as command line argument) philosophers who spend their time either thinking or eating. They sit around a circular table. Food is kept on the middle of the table and a chopstick is placed in between each philosopher.

Philosophers think for some time during which they do not interact with others. Once they are hungry, they pick up the chopsticks on the right and left to eat (one after another if both are available). If any of the chopsticks are not available, they go back to thinking and check after some time. When a hungry philosopher has both chopsticks at the same time, he eats without releasing the chopsticks.

When he is finished eating, he puts down both chopsticks and starts thinking again. Implementation Each philosopher should be implemented as a thread.

Each philosopher thinks for 50- 100 milliseconds at a time (you can pick a random number from this range in every iteration) and eats for 100 milliseconds. Each philosopher must eat 5 times. Use the concept of semaphores for the synchronization between the threads.

And you can use mutex to execute a set of instructions atomically. Print the messages: (Print the messages as it is, It will be easier for TAs to evaluate).