Question: Five philosophers are seated around a circular table ( as illustrated in the figure below ) : Each philosopher has a plate of food that

Five philosophers are seated around a circular table (as illustrated in the figure
below):
Each philosopher has a plate of food that needs two forks to eat it.
Between each pair of plates is one fork.
The life of a philosopher consists of alternate periods of eating and thinking.
When a philosopher gets hungry, he tries to acquire his left and right forks,
one at a time, in either order.
If successful in acquiring two forks, he eats for a while, then puts down the
forks, and continues to think.
Implement the dining-philosophers problems using pthreads, and:
Semaphores
(4 marks)
Mutex Locks (pthread_mutex xa)
(4 marks)
Test and Set Lock
(4 marks)
Peterson's solution
(4 marks)Sample output:Five philosophers are seated around a circular table (as illustrated in the figure
below):
Each philosopher has a plate of food that needs two forks to eat it.
Between each pair of plates is one fork.
The life of a philosopher consists of alternate periods of eating and thinking.
When a philosopher gets hungry, he tries to acquire his left and right forks,
one at a time, in either order.
If successful in acquiring two forks, he eats for a while, then puts down the
forks, and continues to think.
Implement the dining-philosophers problems using pthreads, and:
Semaphores
(4 marks)
Mutex Locks (pthread_mutex xa)
(4 marks)
Test and Set Lock
(4 marks)
Peterson's solution
(4 marks)Five philosophers are seated around a circular table (as illustrated in the figure
below):
Each philosopher has a plate of food that needs two forks to eat it.
Between each pair of plates is one fork.
The life of a philosopher consists of alternate periods of eating and thinking.
When a philosopher gets hungry, he tries to acquire his left and right forks,
one at a time, in either order.
If successful in acquiring two forks, he eats for a while, then puts down the
forks, and continues to think.
Implement the dining-philosophers problems using pthreads, and:
Semaphores
Mutex Locks (pthread mutex t)
Test and Set Lock
Peterson's solution
Sample output:
Philosopher 0 is thinking
Philosopher 1 is thinking
Philosopher 2 is thinking
Philosopher 3 is thinking
Philosopher 4 is thinking
Philosopher 0 got right fork
Philosopher 0 got left fork 1
Philosopher 0 is eating
Philosopher 0 dropped forks 0 and 1
Philosopher 4 got right fork 4
Philosopher 4 got left fork 0
Philosopher 4 is eating
Philosopher 3 got right fork 3
Philosopher 3 dropped fork 3
Philosopher 4 dropped forks 4 and 0
Philosopher 1 got right fork 1
Philosopher 1 got left fork 2
Philosopher 1 is eating
Philosopher 4 got right fork 4
Philosopher 4 got left fork 0
Philosopher 4 is eating
Philosopher 2 is thinking
Philosopher 2 is thinking
Philosopher 1 dropped forks 1 and 2
Philosopher 4 dropped forks 4 and 0
Philosopher got right fork
Philosopher got left fork 1
Philosopher is eating
Philosopher 0 dropped forks 0 and 1
Philosopher 1 got right fork 1
Philosopher 1 got left fork 2
Philosopher 1 is eating
Philosopher 1 dropped forks 1 and 2
Philosopher 3 got right fork 3
Philosopher 3 got left fork 4
Philosopher 3 is eating
Philosopher 4 is thinking
Philosopher got right fork
Philosopher 0 got left fork 1
Philosopher 0 is eating
Philosopher 3 dropped forks 3 and 4
Philosopher 2 got right fork 2
Philosopher 2 got left fork 3
Philosopher 2 is eating
Dhil nsonher 0 dronned forlks 0 and 1
 Five philosophers are seated around a circular table (as illustrated in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!