{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10-Deadlocks_I_2spp

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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)
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
9 Problems with Semaphores Wrong use of semaphore operations: semaphores A and B , initialized to 1 P 0 P 1 wait (A); wait(B) wait (B); wait(A) ! Deadlock signal (mutex) …. wait (mutex) ! violation of mutual exclusion wait (mutex) wait (mutex) !
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern