11_Deadlocks_II_2spp

11_Deadlocks_II_2spp - CSC 4103 - Operating Systems Fall...

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

View Full Document Right Arrow Icon
1 CSC 4103 - Operating Systems Fall 2009 Tevfik Ko ! ar Louisiana State University September 29 th , 2009 Lecture - XI Deadlocks - II 2 Roadmap • Classic Problems of Synchronization Bounded Buffer Readers-Writers Dining Philosophers Sleeping Barber • Deadlock Prevention
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 Classical Problems of Synchronization • Bounded-Buffer Problem • Readers and Writers Problem • Dining-Philosophers Problem • Sleeping Barber Problem 4 Bounded-Buffer Problem Shared buffer with N slots to store at most N items Producer processes data items and puts into the buffer Consumer gets the data items from the buffer Variable empty keeps number of empty slots in the butter Variable full keeps number of full items in the buffer
Background image of page 2
5 Bounded Buffer – 1 Semaphore Soln The structure of the producer process int empty=N, full=0; do { // produce an item wait (mutex); if (empty> 0){ // add the item to the buffer empty --; full++; } signal (mutex); } while (true); 6 Bounded Buffer – 1 Semaphore Soln The structure of the consumer process do { wait (mutex); if (full>0){ // remove an item from buffer full--; empty++; } signal (mutex); // consume the removed item } while (true); consume non-existing item!
Background image of page 3

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

View Full DocumentRight Arrow Icon
7 Bounded Buffer – 1 Semaphore Soln - II The structure of the producer process int empty=N, full=0; do { // produce an item while (empty == 0){} wait (mutex); // add the item to the buffer empty --; full++; signal (mutex); } while (true); 8 Bounded Buffer – 1 Semaphore Soln - II The structure of the consumer process do { while (full == 0){} wait (mutex); // remove an item from buffer full--; empty++; signal (mutex); // consume the removed item } while (true); * Mutual Exclusion not preserved!
Background image of page 4
9 Bounded Buffer – 2 Semaphore Soln The structure of the producer process do { // produce an item wait (empty); // add the item to the buffer signal (full); } while (true); 10 Bounded Buffer – 2 Semaphore Soln The structure of the consumer process do { wait (full); // remove an item from buffer signal (empty); // consume the removed item } while (true); * Mutual Exclusion not preserved!
Background image of page 5

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

View Full DocumentRight Arrow Icon
11 Bounded Buffer - 3 Semaphore Soln • Semaphore mutex for access to the buffer, initialized to 1 • Semaphore full (number of full buffers) initialized to 0 • Semaphore empty (number of empty buffers) initialized to N 12 Bounded Buffer - 3 Semaphore Soln The structure of the producer process do { // produce an item wait (empty); wait (mutex); // add the item to the buffer signal (mutex); signal (full);
Background image of page 6
Bounded Buffer - 3 Semaphore Soln The structure of the consumer process do { wait (full); wait (mutex); // remove an item from buffer signal (mutex); signal (empty); // consume the removed item 14 Readers-Writers Problem Multiple Readers and writers concurrently accessing the same database. Multiple Readers accessing at the same time --> OK
Background image of page 7

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

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

This note was uploaded on 10/01/2011 for the course CSC 4103 taught by Professor Ullmer,b during the Fall '08 term at LSU.

Page1 / 18

11_Deadlocks_II_2spp - CSC 4103 - Operating Systems Fall...

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

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