# 11_Deadlocks_II - CSC 4103 Operating Systems Fall 2009...

This preview shows pages 1–4. Sign up to view the full content.

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 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 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!

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

View Full Document
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! 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! 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);
13 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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

11_Deadlocks_II - CSC 4103 Operating Systems Fall 2009...

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

View Full Document
Ask a homework question - tutors are online