• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

solution to the dining philosopher problem

Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at http://www.xprogramming.com/xpmag/acsDiningPhilosophers.htm
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic