Jump to content
  • Advertisement

Archived

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

xxx_shinobi

Dining Philosophers Problem

This topic is 5530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
I figured, I remember doing this one back in school. Any particular reason you just aren''t doing this one yourself?

It only takes 50 or so lines as I recall.

Share this post


Link to post
Share on other sites
WPI is an institude,not a school. Anyway,do you know an efficient algorithm to my problem cos i have now power and time for it :-)

Share this post


Link to post
Share on other sites
my C is a bit rusty, but here goes:

  
void dine(int n)
{
if(n==0)
{
printf("Fuck it, let''s order pizza\n");
}
else
{
printf("I want pepperoni!\n");
}
}

int main()
{
for(int i=0;i<5;i++)
{
if(fork())
{
dine(i);
return 0;
}
}
return 0;
}

Share this post


Link to post
Share on other sites
Hey, we all called it a ''school'' while we were going there.

If you don''t have to worry about fairness, it''s sufficient to represent each utensil as a binary semaphore. You also add an additional semaphore you need to lock before picking up any utensils. That''ll make your philosophers eat one at a time and keep them from getting deadlocked.

Share this post


Link to post
Share on other sites
utensil[0...4]

while(true)
{
think();
test(#utensils);
test(utensil);
take(utensil[i]);
test(utensil[i+1 % 5]);
take (utensil[i+1 % 5]);
eat();
put_back(utensil[i]);
free(utensil[i]);
put_back(utensil[i + 1 % 5]);
free(utensil[i + 1 % 5]);
free(#utensils);
}




[edited by - Raab314159 on May 28, 2003 3:14:11 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!