Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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)
0
killer455
Asked:
killer455
2 Solutions
 
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
 
ozoCommented:
Algorithm 1 suffers from deadlock.
Algorithm 3 can suffer from starvation.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now