1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Dinning Philosophers' Problem Using Conditional Variables

  1. May 11, 2013 #1
    1. The problem statement, all variables and given/known data
    I can't see where the problem is in the following pseudo-code.
    I recall from class that the problem is based on the signal calls and wait call in pickup() and putdown()

    Thank you.

    2. Relevant equations
    Code (Text):

    class Monitor R()
    {
        bool forks[5]; // all true

        condition c[5];

        void pickup(i)
        {
            left =i;
            right=(i+1)%5;

            if (forks[left])
                forks[left]=F;

            if (forks[right])
                forks[right]=F;

            while( forks[left]==F || forks[right]==F )
                wait(c[i])

            forks[left]=F;
            forks[right]=F;
        }

        void putdown(i)
        {
            lphil=(i+4)%5;
            rphil=(i+1)%5;

            left=i;
            right=(i+1)%5;

            forks[left]=T;
            forks[right]=T;

            signal( c[lphil]);
            signal( c[rphil] );

        }
    }
     
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted