Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > solution to the dinning philosopher problem

Reply
Thread Tools

solution to the dinning philosopher problem

 
 
Yan Zhou
Guest
Posts: n/a
 
      09-02-2004
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


 
Reply With Quote
 
 
 
 
steve
Guest
Posts: n/a
 
      09-02-2004
On Fri, 3 Sep 2004 02:32:57 +0800, Yan Zhou wrote
(in article <(E-Mail Removed)>):

> 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.

 
Reply With Quote
 
 
 
 
Mark A. Washburn
Guest
Posts: n/a
 
      09-02-2004
"Yan Zhou" <(E-Mail Removed)_REMOVE> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      09-10-2004
Yan Zhou wrote:

> 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

--
Grant Wagner <(E-Mail Removed)>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A philosopher's final answer chuckcar Computer Support 11 03-16-2009 04:35 AM
Re: A philosopher's final answer Shel-hed Computer Support 0 03-14-2009 04:06 AM
Re: A philosopher's final answer thanatoid Computer Support 1 03-14-2009 02:07 AM
Re: A philosopher's final answer Moog Computer Support 1 03-14-2009 12:04 AM
Microsoft cannot withstand Linux pyramid: philosopher Girardet Au79 Computer Support 0 04-13-2006 01:05 PM



Advertisments