10-Deadlocks_I_2spp

10-Deadlocks_I_2spp - 1 CSE 421/521 - Operating Systems...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 421/521 - Operating Systems Fall 2011 Tevfik Ko ş ar University at Buffalo October 4 th , 2011 Lecture - X Process Synchronization & Deadlocks 2 Roadmap • Classic Problems of Synchronization – Readers and Writers Problem – Dining-Philosophers Problem – Sleeping Barber Problem • Deadlocks 3 Readers-Writers Problem • Multiple Readers and writers concurrently accessing the same database. • Multiple Readers accessing at the same time --> OK • When there is a Writer accessing, there should be no other processes accessing at the same time. 4 Readers-Writers Problem • The structure of a writer process do { wait (wrt) ; // writing is performed signal (wrt) ; } while (true) 3 Readers-Writers Problem • Multiple Readers and writers concurrently accessing the same database. • Multiple Readers accessing at the same time --> OK • When there is a Writer accessing, there should be no other processes accessing at the same time. 4 Readers-Writers Problem • The structure of a writer process do { wait (wrt) ; // writing is performed signal (wrt) ; } while (true) 5 Readers-Writers Problem (Cont.) • The structure of a reader process do { wait (mutex) ; readercount ++ ; if (readercount == 1) wait (wrt) ; signal (mutex) // reading is performed wait (mutex) ; readercount - - ; if readercount == 0) signal (wrt) ; signal (mutex) ; } while (true) 6 Dining Philosophers Problem • Five philosophers spend their time eating and thinking. • They are sitting in front of a round table with spaghetti served. • There are five plates at the table and five chopsticks set between the plates. • Eating the spaghetti requires the use of two chopsticks which the philosophers pick up one at a time. •Philosophers do not talk to each other. • Semaphore chopstick [5] initialized to 1 7 Dining-Philosophers Problem (Cont.) • The structure of Philosopher i : Do { wait ( chopstick[i] ); wait ( chopStick[ (i + 1) % 5] ); // eat signal ( chopstick[i] ); signal (chopstick[ (i + 1) % 5] ); // think } while (true) ; 8 To Prevent Deadlock • Ensures mutual exclusion, but does not prevent deadlock • Allow philosopher to pick up her chopsticks only if both chopsticks are available (i.e. in critical section) • Use an asymmetric solution: an odd philosopher picks up first her left chopstick and then her right chopstick; and vice versa 9 Problems with Semaphores • Wrong use of semaphore operations: – semaphores A and B , initialized to 1 P P 1 wait (A); wait(B)...
View Full Document

This document was uploaded on 11/12/2011.

Page1 / 14

10-Deadlocks_I_2spp - 1 CSE 421/521 - Operating Systems...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online