Exp8 102 JayeshRuchandani
Exp8 102 JayeshRuchandani
------------------------------------------------------------------------------------------------------------
Course Code: CSL403 Name: Operating System Lab
Class: SE Semester: IV
EXPERIMENT NO 8
Theory:
Consider five philosophers who spend their lives thinking and eating. The
philosophers share a circular table surrounded by five chairs, each belonging to one
philosopher. In the center of the table is a bowl of rice, and the table is laid with
five single chopsticks.
When a philosopher thinks, she does not interact with her colleagues. From time to
time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest
to her (the chopsticks that are between her and her left and right neighbors). A
philosopher may pick up only one chopstick at a time. Obviously, she cannot pick up
a chopstick that is already in the hand of a neighbor. When a hungry philosopher has
both her chopsticks at the same time, she eats without releasing her chopsticks. When
she is finished eating, she puts down both of her chopsticks and starts thinking again.
The solution is to represent each chopstick with a semaphore. A philosopher tries to
grab a chopstick by executing a wait () operation on that semaphore; she releases her
chopsticks by executing the signal() operation on the appropriate semaphores. Thus,
the shared data are
S22-102 Jayesh Ruchandani
semaphore chopstick[5];
where all the elements of chopstick are initialized to 1.
Program:
S22-102 Jayesh Ruchandani
+
S22-102 Jayesh Ruchandani
OUTPUT:
Conclusion: Hence, we have studied and implemented the the concept of Dining
Philosopher’s Problem.