General_Trageto Posted February 25, 2003 Share Posted February 25, 2003 I'm working on a C++ simulation of a problem called the 'dining philosophers'. It's dealing with the synchronisation of multiple threads sharing a number of resources. Does anybody know something about the code implementation or where I can find valuable information? Link to comment Share on other sites More sharing options...
Keyan Farlander Posted February 26, 2003 Share Posted February 26, 2003 Java textbooks usually talk about that. I don't know how you're planning to do multiple threads in C++, so it may not be very similar. Just google "dining philosophers" and you should find tons. Link to comment Share on other sites More sharing options...
Zargon Posted February 26, 2003 Share Posted February 26, 2003 google > college Link to comment Share on other sites More sharing options...
General_Trageto Posted February 26, 2003 Author Share Posted February 26, 2003 I already looked at google. Most of the stuff I found was crap or for Java or for Linux. *sigh* Link to comment Share on other sites More sharing options...
Flying Beastie Posted February 26, 2003 Share Posted February 26, 2003 And for zee dinner tonight, Socrates will be enjoying the lovely couscous, Sartre and de Beauvoir will be sharing zee fresh lobster platter with a side-order of Caesar salad, and Nietzche is having zee delicious roast venison and garlic bread, with white wine. Bonappetit! Link to comment Share on other sites More sharing options...
General_Trageto Posted February 26, 2003 Author Share Posted February 26, 2003 If I remember right, the classic case, stated by Dijkstra had spaghetti for all of them Link to comment Share on other sites More sharing options...
Jabba The Hunt Posted February 26, 2003 Share Posted February 26, 2003 could someone explain the problem to me please? Link to comment Share on other sites More sharing options...
Keyan Farlander Posted February 26, 2003 Share Posted February 26, 2003 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 More sharing options...
Lujayne Posted February 26, 2003 Share Posted February 26, 2003 Are you..talking..words? Link to comment Share on other sites More sharing options...
Rogue Nine Posted February 26, 2003 Share Posted February 26, 2003 I've learned never to look at any of Keyan's posts in a mathematics-related thread. My head will hurt. Link to comment Share on other sites More sharing options...
Tierce Posted February 26, 2003 Share Posted February 26, 2003 ditto, the more you read it and the more you try to understand it, the more it hurts. Link to comment Share on other sites More sharing options...
Cmdr. Cracken Posted February 27, 2003 Share Posted February 27, 2003 if there so smart, why don't they just take turns? ^_^ Link to comment Share on other sites More sharing options...
General_Trageto Posted February 27, 2003 Author Share Posted February 27, 2003 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 More sharing options...
Lujayne Posted February 27, 2003 Share Posted February 27, 2003 I dunno, I think Cracken's actually the voice of reason in this thread. n_n ...Scary. O_o Link to comment Share on other sites More sharing options...
Keyan Farlander Posted February 27, 2003 Share Posted February 27, 2003 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 More sharing options...
Rogue Nine Posted February 27, 2003 Share Posted February 27, 2003 Originally posted by Lujayne I dunno, I think Cracken's actually the voice of reason in this thread. n_n ...Scary. O_o Yeah, you can say that maybe...what? Once every few decades? Link to comment Share on other sites More sharing options...
Commander 598 Posted February 27, 2003 Share Posted February 27, 2003 Have I inhaled some odd fumes, or did Niner change his Avatar and his title is now readable... Link to comment Share on other sites More sharing options...
Rogue Nine Posted February 27, 2003 Share Posted February 27, 2003 It's always been readable, you illiterate fool, just in a different language. Link to comment Share on other sites More sharing options...
Jabba The Hunt Posted February 27, 2003 Share Posted February 27, 2003 sorry to be solving the problem like a vb'er but can't you just use some sort of loop? Link to comment Share on other sites More sharing options...
Keyan Farlander Posted February 27, 2003 Share Posted February 27, 2003 Um...what are you talking about Jabba? The point is that it's an example for multithreading. One thread for each philosopher. Link to comment Share on other sites More sharing options...
General_Trageto Posted February 27, 2003 Author Share Posted February 27, 2003 Right. And the aim is to get a max number of philosophers eating(2 that is). A loop or a token would result in only one being able to eat at a time. Also, these are all different processes - each thread does something different(theoretically), and therefore takes a different amount of time. Link to comment Share on other sites More sharing options...
Flying Beastie Posted February 27, 2003 Share Posted February 27, 2003 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 More sharing options...
Jabba The Hunt Posted February 27, 2003 Share Posted February 27, 2003 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 More sharing options...
Gold leader Posted February 27, 2003 Share Posted February 27, 2003 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 More sharing options...
General_Trageto Posted February 28, 2003 Author Share Posted February 28, 2003 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 , he'd never expect anything like that! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.