solution to the dinning philosopher problem

Discussion in 'Java' started by Yan Zhou, Sep 2, 2004.

  1. Yan Zhou

    Yan Zhou Guest

    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
     
    Yan Zhou, Sep 2, 2004
    #1
    1. Advertising

  2. Yan Zhou

    steve Guest

    On Fri, 3 Sep 2004 02:32:57 +0800, Yan Zhou wrote
    (in article <>):

    > 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.
     
    steve, Sep 2, 2004
    #2
    1. Advertising

  3. "Yan Zhou" <_REMOVE> wrote in message news:<>...
    > 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
     
    Mark A. Washburn, Sep 3, 2004
    #3
  4. Yan Zhou

    Grant Wagner Guest

    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 <>
     
    Grant Wagner, Sep 10, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Francis
    Replies:
    0
    Views:
    435
    Andrew Francis
    Jun 28, 2006
  2. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    Solution file not in the solution folder

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Sep 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,126
    Laurent Bugnion
    Sep 12, 2006
  3. , India
    Replies:
    17
    Views:
    1,093
    James Kanze
    Oct 1, 2007
  4. Replies:
    8
    Views:
    523
  5. email55555 email55555

    [SOLUTION] Ruby Quiz #14 LCD Numbers ( solution #2 )

    email55555 email55555, Jan 9, 2005, in forum: Ruby
    Replies:
    16
    Views:
    294
    David Tran
    Jan 10, 2005
Loading...

Share This Page