solution to the dinning philosopher problem

Y

Yan Zhou

Hi there,

I have code a program that solves the dinning philosopher problem. But there
is still room to improve.

My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.

The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.

I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.

Any suggestion?
Yan
 
S

steve

Hi there,

I have code a program that solves the dinning philosopher problem. But there
is still room to improve.

My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.

The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.

I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.

Any suggestion?
Yan

so in your country you eat with 2 forks do you?

this solution has been posted on suns website, but there they eat with
chopsticks.

sounds like homework.
 
M

Mark A. Washburn

Yan Zhou said:
Hi there,

I have code a program that solves the dinning philosopher problem. But there
is still room to improve.

My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.

The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.

I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.

Any suggestion?
Yan

JCSP demonstrates an exemplary method for multiple philosophers problem.

http://www.cs.ukc.ac.uk/projects/ofa/jcsp/

maw
 
G

Grant Wagner

Yan said:
Hi there,

I have code a program that solves the dinning philosopher problem. But there
is still room to improve.

My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.

The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.

I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.

Any suggestion?
Yan

Feed the philosopher to a real scientist and you've solved two problems:

1) you've gotten rid of the useless philosopher
2) you've fed a starving scientist you can actually accomplish something
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top