![]() |
Regarding Dining Philosophers Problem
Hi there,
I'm trying to implement the Dining Philosophers problem, using a virtual distributed system, in which a host creates a number of virtual sites and communication means between them (message passing). Hence, every site created should be thought of a "philosopher", and each will try to pick the forks (if available). I have already implemented the whole Virtual Distributed System, and communications means, I am able to create the sites. But I need a way to allow the created "philosophers" to execute a the same time, trying to pick the forks...i.e, I don't want it to happen in sequential way (loop iteration, one after the other), it needs to be like some kind of a race, the one who gets there first can pick up the fork...Do you know what i mean?? Anybody has any ideas?? Thanks. |
Re: Regarding Dining Philosophers Problem
>>Do you know what i mean??
I haven't the foggest idea of what you mean :) |
Re: Regarding Dining Philosophers Problem
Simultaneous execution generally means multiple execution threads running in parallel. Look up threading for your particular OS (http://www.yolinux.com/TUTORIALS/Lin...ixThreads.html doesn't look bad for Linux) and get crackin'.
|
Re: Regarding Dining Philosophers Problem
I have finally written the code to solve the Dining philosopher problem using a virtual distributed system with message passing (as a mean of communication between each created site). However, when i run the program, it hangs.
The following is the code in which sites are created and the dining philosopher problem is handled using semaphores. I can successfully create sites ( I have tested it) so i know the problem comes from the Philo() function. :
#include <stdio.h>The output it produces is: http://img186.imageshack.us/my.php?image=outputxm7.jpg it doesnt seem to execute the getforks(),eat(), putforks() functions.... Anybody can help me out with it? |
Re: Regarding Dining Philosophers Problem
:
int main(argc, argv):
int main(int argc, char* argv[])I know my comments don't help solve your problem, but it will take some time to sift through your code. |
Re: Regarding Dining Philosophers Problem
hehe...actually, some part of the main program was given to me, and i wrote the Philo function, and all other functions related to it.
Now, I can get some of the philosophers to eat, but then it deadlocks. I want to solve the deadlock, but not sure how. I wanna try to force preemption of ressources: i.e, if one philosopher holds 1 chopstick, but can't get the other one, then he has to release the one he already holds... I guess this has to be done in the get_forks function: :
void get_forks(int ph_id)Any ideas?? |
Re: Regarding Dining Philosophers Problem
yes i got what you mean. Just can you elaborate what you want. Do you need another code that i have! Free!
|
Re: Regarding Dining Philosophers Problem
yours code is tooo much big, can be made smaller!
|
Re: Regarding Dining Philosophers Problem
umm, yeah i guess my code is too big, but I don't know how to make it smaller...Also, i tried to edit it to preempt philosophers to release the left chopstick, whenever a request for a right chopstick could not be granted,...but i ave another problem, i can't seem to keep track on the number of eating phases...i mean everytime a philosopher eats, a counter should be incremented, and a there should be a total of 10 eating phases. Bu i cant't seem to correctly update the global variable (I am using a global variable count=0)
and then: :
while(count<10)Then everytime a philosopher eats, it increments the global variable by 1...but i keep getting an output similar to this: Philosopher 2 is eating meal 1 for 3 seconds. ... Philosopher 1 is eating meal 1 for 2 seconds. Philosopher 4 is eating meal 1 for 4 seconds. .... Philosopher 2 is eating meal 2 for 5 seconds. Philosopher 4 is eating meal 2 for 3 seconds. .... Any ideas? |
| All times are GMT -5. The time now is 4:23 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC