Jump to content

Home

Dining Philosophers...


General_Trageto

Recommended Posts

There are five philosphers sitting at a round table, and all they do is think and eat. There are also five sticks, such that each philosopher has one to his left and one to his right. In order to eat, a philosopher must have both of the sticks that are next to him (the one on his left and the one on his right).

 

The issue is that if each philosopher grabs the stick to his right, they will all wait forever for the sticks on their left, but they will never be available, obviously, and so they all starve.

Link to comment
Share on other sites

However, what Keyan said, is exactly correct - only that the deadlock resulting in taking only one fork/chopstick/whatever is only one of the problems.

 

Let's put it like this:

You have 5 Threads

=parts of processes, actions

You have a limited amount or resources

= e.g. printer, CPU, memory

To run each thread needs two resources, wich will result in concurrences. Dijkstra has developed this problem and an algorithm which solves it. And so shall I now, as well

Link to comment
Share on other sites

Originally posted by General Trageto

However, what Keyan said, is exactly correct - only that the deadlock resulting in taking only one fork/chopstick/whatever is only one of the problems.

 

Let's put it like this:

You have 5 Threads

=parts of processes, actions

You have a limited amount or resources

= e.g. printer, CPU, memory

To run each thread needs two resources, wich will result in concurrences. Dijkstra has developed this problem and an algorithm which solves it. And so shall I now, as well

 

Yes, there are additional issues such as "fairness" as well. Can't let just one of them starve, either. That would be sad. Philosophers shouldn't starve. What a morbid example :(

Link to comment
Share on other sites

Originally posted by Keyan Farlander

There are five philosphers sitting at a round table, and all they do is think and eat. There are also five sticks, such that each philosopher has one to his left and one to his right. In order to eat, a philosopher must have both of the sticks that are next to him (the one on his left and the one on his right).

 

The issue is that if each philosopher grabs the stick to his right, they will all wait forever for the sticks on their left, but they will never be available, obviously, and so they all starve.

 

*watches Ayn Rand use her stick to bludgeon the person to her left and take his stick*

 

*she then clubs the person to her right, and gives his stick to the next person over*

 

Two people eating, two people unconscious, and only one left to complain.

 

;)

 

I miss Zoomie.

Link to comment
Share on other sites

A computer can only run 1 process at a time anyway, thats why a multiprogramming (or multitasking) enviroment is the APPARENT simultaneous execution of two or more process's, so you see in the context of programming you can't have more than one thread running at a time. (although ill agree you can have more than one in the running or runnable status :)). Now i'll agree the point of the exercise is lost when you start using a loop but surely it would work just aswell (im assuming here the C++ will allow you control of whether the loop is running/runnable or not) (when i say a loop I dont mean just 3 lines of code, you would obviously have to add code to determin which threads need more time etc)

Link to comment
Share on other sites

One of my subjects in the previous semester was Operations Research. One the fields it covers is the multiple sources, multiple sinks problem. Perhaps it is possible to describe "the dining philosophers" as a linear programming problem and solve it with the simplex method? In a dynamical sense, that is.

Link to comment
Share on other sites

Hmmm, possible, I have no clue about operatioins research(I'm just in 1st semester). However, to achief the result I want, I need to work with mutexes. My problem is the implementation.

 

Though ... I like your idea, Flying Beastie! I could surely make some big impression to my prof :D, he'd never expect anything like that!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...