Dining Philosopher Problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Velan
Posts: 5
Joined: Sat Sep 24, 2005 11:00 pm

Dining Philosopher Problem

Post by Velan »

In Dining Philosopher problem, I have doubts in Semaphore. Which one of the following is better and suited for what?

1) Applying Semaphores for Other processes (i.e for Philosophers)
2) Applying Semaphore for Other Resources (i.e for Forks).
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Dining Philosopher Problem

Post by Legend »

Well, do you want to use a semaphore that a philosopher has first to get before he can pick up a fork?

Or a semaphore per philosopher?
*post*
Velan
Posts: 5
Joined: Sat Sep 24, 2005 11:00 pm

Re: Dining Philosopher Problem

Post by Velan »

I have implemented both the methods.

1) Putting semaphore for all the forks.
2) Putting semaphore for every philosophers.

But only one mothod is possible at a time. I would like to which method to choose for efficiency and differentiate.
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Dining Philosopher Problem

Post by Legend »

One semaphore for all forks ... as a result only one philosopher can eat at a time?
*post*
Velan
Posts: 5
Joined: Sat Sep 24, 2005 11:00 pm

Re: Dining Philosopher Problem

Post by Velan »

It's not like that. If a philosopher wants to eat, he will put a semphore for LEFT and RIGHT forks. This is one way.

If a philospher wants to eat, he will put a semaphore for LEFT and RIGHT philosophers, provided both of them are not eating.

For the above two, I want to know which one will be efficient and better.
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Dining Philosopher Problem

Post by Legend »

The first one sounds like the classical case that has a dead lock problem, doesn't it?
*post*
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: Dining Philosopher Problem

Post by Da_Maestro »

Either way is just as efficient.

Though with the semaphores per philosopher implementation you might get syncronisation problems...

Adam
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
Post Reply