Condition necessary for deadlock to occur

Chapter 5

1) In Peterson's Algorithm, if both processes want to enter the critical section, what keeps starvation from occurring?

2) How does interrupt disabling provide mutual exclusion?

3) In the Compare & Swap instruction, why must the instruction execute atomically?

Chapter 6

4) Why is the mutual exclusion condition necessary for deadlock to occur?

5) Is the following setup safe or unsafe according to the Banker's algorithm?
Show your work and explain your result.

   R1  R2           R1  R2

P1  3   2        P1  2   1
P2  2   3        P2  1   1

Claim matrix     Allocation matrix


   R1  R2           R1  R2
    3   3            0   1

Resource vector Available vector

6) Coordinate the actions of the two threads below by inserting wait/signal commands
on semaphores so that the Give_order() happens first, then the Take_order(),
then the Serve_meal(), then the Eat_meal(). You can assume one thread each.

Customer            Waiter

 Give_order()       Take_order()

 Eat_meal()         Serve_meal()

Sample Solution