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?
 
ozoCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
killer455Author Commented:
What about algorithm 2?
0
 
MistobaanCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.