View Single Post
Old Mar 24th, 2008, 5:57 PM   #9
joeserhal
Newbie
 
Join Date: Feb 2008
Posts: 18
Rep Power: 0 joeserhal is on a distinguished road
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)
	      {
	        think(MySID);
	        get_forks(MySID);
	        eat(MySID,i);
	        put_forks(MySID);
	      }

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?
joeserhal is offline   Reply With Quote