The operation xwait means that the process invoking this operation is suspended

The operation xwait means that the process invoking

This preview shows page 56 - 58 out of 58 pages.

± The operation x.wait; means that the process invoking this operation is suspended until another process invokes x.signal; ± The x.signal operation resumes exactly one suspended process. If no process is suspended, then the signal operation has no effect.
Image of page 56
Dining Philosophers type dining-philosophers = monitor var state : array [0..4] of ( thinking , hungry , eating ); var self : array [0..4] of condition ; // condition where philosopher I can delay himself when hungry but // is unable to obtain chopstick(s) procedure entry pickup ( i :0..4); begin state [ i ] := hungry ; test ( i ); //test that your left and right neighbors are not eating if state [ i ] <> eating then self [ i ]. wait ; end ; procedure entry putdown ( i :0..4); begin state [ i ] := thinking ; test ( i + 4 mod 5 ); // signal left neighbor test ( i + 1 mod 5 ); // signal right neighbor end ;
Image of page 57
Dining Philosophers (cont.) procedure test ( k :0..4); begin if state [ k + 4 mod 5] <> eating and state [ k ] = hungry and state [ k + 1 mod 5] <> eating then begin state [ k ] := eating ; self [ k ]. signal ; end; end ; begin for i := 0 to 4 do state [ i ] := thinking ; end;
Image of page 58

You've reached the end of your free preview.

Want to read all 58 pages?

  • One '20
  • producer, monitor, Semaphore

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors