1Overview Assignment 8: hints Assignment 7: solution Deadlocks See sample solution on the web
2A8 Ex1 – Barrier Objects synchronize processes “checkpoint”: continue only when all processes are therecheckpointcheckpointcheckpointBarrier = OBJECT Init(count); Sync;PROCESS:FOR i := 0 TO Max DODoPhase(i);barrier.SyncEND
3Barrier, Example P1 P2 P3 // code before the barrier Barrier.synchronize()// code after the barrier
4A8 Ex1 - TaskWrite a barrier implementation in the (reasonable) language of your choice.The Barrier object should have the following methods:Initialize: to specify how many process are to be synchronized by this barrier.Synchronize: wait until all processes reached the barrier.
5A8 Ex2 – Deadlocks Coffman conditions Solutions Mutual exclusion in resource usageHolding a resource and waitingNo preemption of resources possibleCircular waitSolutionsuse protocol that ensures the system will never deadlockdetect deadlock and recoverignore (...and reboot)
6Deadlocks Transactions in a bank Deadlock avoidance: move $ from x to yconcurrent systemacquire lock on both accounts, then perform transferDeadlock avoidance:mutual exclusion (accounts are locked)no preemption (once locked, unlock only after transfer)hold and wait (first account locked, waiting for second one)must avoid circular wait..... HOW?
7Deadlocks: example Example: p1: lock(x, y); p2: lock(y, x); Scenario: p1 locks xp2 locks yp1 tries to lock y and waitsp2 tries to lock x and waitsDEADLOCK
8A8 Ex3 – Baboons Problem Part a): avoid deadlocks using semaphores. more than one baboon can cross (but only in one direction)if two (or more) baboons cross in different directions we have a deadlock.Part a): avoid deadlocks using semaphores.Part b): avoid starvation.