10-Deadlocks_I

10-Deadlocks_I - 1 CSE 421/521 - Operating Systems Fall...

Info iconThis preview shows pages 1–3. 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
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) 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) wait (B); wait(A) ! Deadlock signal (mutex) . wait (mutex) ! violation of mutual exclusion wait (mutex) wait (mutex) ! Deadlock Omitting of wait (mutex) or signal (mutex) (or both) ! violation of mutual exclusion or deadlock 10 Semaphores inadequate in dealing with deadlocks do not protect the programmer from the easy mistakes of taking a semaphore that is already held by the same process, and forgetting to release a semaphore that has been taken mostly used in low level code, eg. operating systems the trend in programming language development, though, is towards more structured forms of synchronization, such as monitors 11 Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within the monitor at a time monitor monitor-name...
View Full Document

Page1 / 5

10-Deadlocks_I - 1 CSE 421/521 - Operating Systems Fall...

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

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