Presentation on theme: "1 Overview Assignment 8: hints Deadlocks Assignment 7: solution See sample solution on the web."— Presentation transcript:
1 Overview Assignment 8: hints Deadlocks Assignment 7: solution See sample solution on the web
2 A8 Ex1 – Barrier Objects synchronize processes “checkpoint”: continue only when all processes are there checkpoint PROCESS: FOR i := 0 TO Max DO DoPhase(i); barrier.Sync END Barrier = OBJECT Init(count); Sync;
3 Barrier, Example P1 P2 P3 Barrier.synchronize() // code after the barrier // code before the barrier
4 A8 Ex1 - Task Write 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.
5 A8 Ex2 – Deadlocks Coffman conditions Mutual exclusion in resource usage Holding a resource and waiting No preemption of resources possible Circular wait Solutions use protocol that ensures the system will never deadlock detect deadlock and recover ignore (...and reboot)
6 Deadlocks Transactions in a bank move $ from x to y concurrent system acquire lock on both accounts, then perform transfer Deadlock 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?
7 Deadlocks: example Example: p1: lock(x, y); p2: lock(y, x); Scenario: p1 locks x p2 locks y p1 tries to lock y and waits p2 tries to lock x and waits DEADLOCK
8 A8 Ex3 – Baboons Problem 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.