Dining Philosophers problem - easy questions

Could anyone tell me what the pros and cons of the following three solutions to the dining
philosophers problem are?

Algorithm 1:
Wait for left stick to be free.
Pick up left stick.
Wait for right stick to be free.
Pick up right stick.

Algorithm 2:
All philosophers run Algorithm 1,
except philosopher number 5 who runs:

Wait for right stick to be free.
Pick up right stick.
Wait for left stick to be free.
Pick up left stick.

Algorithm 3: Wait for both sticks to be free.
Pick up both sticks (as an atomic operation)
killer455Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
Algorithm 1 suffers from deadlock.
Algorithm 3 can suffer from starvation.
0
 
FeldsparCommented:
The issues that are generally present in multiprogramming systems like this are:
- Deadlock: it wont get to a state where some threads can never run because they are waiting on each other.
- Starvation: a thread doesnt get blocked 'forever' becaue other threads always have the resources it needs
- Fairness: threads get blocked evenly, and no thread is 'favored' over others.  
And like everything, there is also ease of implementation, memory required, overhead, speed, etc.

this page might give you a good guide
http://www.cs.ucsb.edu/~cs170/notes/dphil/
0
 
killer455Author Commented:
This is more of a general answer, could be be more specific to my question regarding those algorithms rather than general info.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
killer455Author Commented:
What about algorithm 2?
0
 
MistobaanConnect With a Mentor Commented:
Alghoritm 2 is the same as 1
it suffers deadlock, Starvation and fairness.
It depends also on how the stick are released.
0
 
ozoCommented:
Algorithm 2 does not suffer deadlock
0
 
mtcmediaCommented:
Algorithm 2 looks like the good one to me :)
0
All Courses

From novice to tech pro — start learning today.