Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6(b): Synchronization.

Slides:



Advertisements
Similar presentations
Module 6: Process Synchronization
Advertisements

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Synchronization Principles Gordon College Stephen Brinton.
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Classical Synchronization Problems. Paradigms for Threads to Share Data We’ve looked at critical sections –Really, a form of locking –When one thread.
Process Synchronization
IPC and Classical Synchronization Problems
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
What we will cover… Process Synchronization Basic Concepts
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Classical Synchronization Problems. Announcements CS 414 grades and solutions available in CMS soon. –Average 74.3 –High of 95. –Score out of 100 pts.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Interrupt Interrupt and Context Switching (Process.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Critical Problem Revisit. Critical Sections Mutual exclusion Only one process can be in the critical section at a time Without mutual exclusion, results.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Synchronization Background The Critical-Section.
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 5: Process Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Synchronization Background The Critical-Section Problem Peterson’s.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Deadlock and Starvation
Chapter 6: Process Synchronization
Process Synchronization
Process Synchronization: Semaphores
Chapter 5: Process Synchronization
Deadlock and Starvation
Chapter 6: Process Synchronization
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic Synchronization
Chapter 7: Synchronization Examples
Presentation transcript:

Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6(b): Synchronization

6.2 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Module 6: Process Synchronization  Semaphores  Types of Semaphores  Implementing Semaphores  Deadlock  Monitors  Barriers  Classic Syncrhonization Problems  Synchronization in Linux  Example: semaphores in pthreads

6.3 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Semaphore  Synchronization tool that does not require busy waiting  Semaphore S – integer variable  Two standard operations modify S: acquire() and release() Originally called P() and V()  from Dutch Proberen and Verhogen (Dijkstra) Also called down() and up() And even wait() and signal()  Higher-level abstraction, less complicated  Can only be accessed via two indivisible (atomic) operations P(S) { while(S ≤ 0) ; S--; } V(S) { S++; }

6.4 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Semaphore Types  Counting semaphore – integer value can range over an unrestricted domain Used for synchronization  Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement Used for mutual exclusion: known as a mutex Process i P(S); Critical Section V(S); Remainder Section

6.5 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Semaphore Implementation  Must guarantee that no two processes can execute P () / acquire () and V () / release () on the same semaphore at the same time  Thus, implementation of these operations becomes the critical section problem again, where the acquire and release code are placed inside the critical section. Could now have busy waiting in critical section implementation But if we know we can’t acquire semaphore, should we busy wait and burn up the CPU?  Note that applications may spend lots of time in critical sections and therefore this is not a good solution.  We’d like a semaphore that sleeps (or at least lets someone else run)

6.6 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Semaphore Implementation with no Busy waiting  With each semaphore there is an associated waiting queue. Each entry in a waiting queue has two data items: value (of type integer) pointer to next record in the list  Two operations: block – place the process invoking the operation on the appropriate waiting queue. wakeup – remove one of processes in the waiting queue and place it in the ready queue.  Potential queuing policies: FIFO, LIFO, undef

6.7 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Semaphore Implementation with no Busy waiting (Cont.)  Implementation of acquire():  Implementation of release():

6.8 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Producer-Consumer Problem  Bounded buffer: size ‘N’ Access entry 0… N-1, then “wrap around” to 0 again  Producer process writes data to buffer Must not write more than ‘N’ items more than consumer “ate”  Consumer process reads data from buffer Should not try to consume if there is no data 01 In Out N-1

6.9 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Solving Producer-Consumer Problem  Solving with semaphores We’ll use two kinds of semaphores We’ll use counters to track how much data is in the buffer  One counter counts as we add data and stops the producer if there are N objects in the buffer  A second counter counts as we remove data and stops a consumer if there are 0 in the buffer Idea: since general semaphores can count for us, we don’t need a separate counter variable  Why do we need a second kind of semaphore? We’ll also need a mutex semaphore

6.10 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Producer-Consumer Problem Shared: Semaphores mutex, empty, full; Init: mutex = 1; /* for mutual exclusion*/ empty = N; /* number empty buf entries */ full = 0; /* number full buf entries */ Producer do {... // produce an item in nextp... P(empty); P(mutex);... // add nextp to buffer... V(mutex); V(full); } while (true); Consumer do { P(full); P(mutex);... // remove item to nextc... V(mutex); V(empty);... // consume item in nextc... } while (true);

6.11 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Implementation of user-level thread mutex lock and unlock. Sample Implementation of Mutexes Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.12 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Common Errors with Semaphores Process i P(S) CS P(S) Process j V(S) CS V(S) Process k P(S) CS A typo. Process I will get stuck (forever) the second time it does the P() operation. Moreover, every other process will freeze up too when trying to enter the critical section! A typo. Process J won’t respect mutual exclusion even if the other processes follow the rules correctly. Worse still, once we’ve done two “extra” V() operations this way, other processes might get into the CS inappropriately! Whoever next calls P() will freeze up. The bug might be confusing because that other process could be perfectly correct code, yet that’s the one you’ll see hung when you use the debugger to look at its state! Process l P(S) If (something) return; CS V(S) Someone forgot to release the semaphore before returning! The next caller will get stuck.

6.13 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Deadlock and Starvation  Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes  Let S and Q be two semaphores initialized to 1 P 0 P 1 S.acquire(); Q.acquire(); Q.acquire(); S.acquire();. S.release(); Q.release(); Q.release(); S.release();  Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended.

6.14 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Monitors  A high-level language abstraction that provides a convenient and effective mechanism for process synchronization  Only one process may be active within the monitor at a time

6.15 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Schematic view of a Monitor  Can think of a monitor as one big lock for a set of operations/ methods  In other words, a language implementation of mutexes  What are the advantages and disadvantages of this approach?

6.16 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots. Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved Producer-Consumer with Monitors

6.17 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots. Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved Producer-Consumer with Monitors (2)

6.18 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Condition Variables  Condition x, y;  Two operations on a condition variable: wait () – a process that invokes the operation is suspended. signal () / notify() – resumes one of processes (if any) that invoked wait ()  Subtleties between condition variables and semaphores: Semaphores have memory: V() will increment the semaphore, even if no one has called P() Condition variables do not: if no one is waiting for a signal() / notify(), it is not saved  Condition variables in monitors: Calling wait() releases the monitor Returning from wait() re-acquires the monitor Does signal() release the monitor? Who runs after a signal() is called?

6.19 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Monitor with Condition Variables

6.20 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Java Synchronization  Java provides synchronization at the language-level.  Each Java object has an associated lock.  This lock is acquired by invoking a synchronized method.  This lock is released when exiting the synchronized method.  Threads waiting to acquire the object lock are placed in the associated entry set for the object lock.

6.21 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Java Synchronization Synchronized insert() and remove() methods

6.22 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Java Synchronization wait/notify()  When a thread invokes wait(): 1. The thread releases the object lock; 2. The state of the thread is set to Blocked; 3. The thread is placed in the wait set for the object.  When a thread invokes notify(): 1. An arbitrary thread T from the wait set is selected; 2. T is moved from the wait to the entry set; 3. The state of T is set to Runnable.

6.23 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Java Synchronization  The call to notify() selects an arbitrary thread from the wait set. It is possible the selected thread is in fact not waiting upon the condition for which it was notified.  The call notifyAll() selects all threads in the wait set and moves them to the entry set.  In general, notifyAll() is a more conservative strategy than notify().

6.24 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Use of a barrier. (a) Processes approaching a barrier. (b) All processes but one blocked at the barrier. (c) When the last process arrives at the barrier, all of them are let through. Barriers Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.25 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Classical Problems of Synchronization  Bounded-Buffer/Producer-Consumer Problem  Readers and Writers Problem  Dining-Philosophers Problem

6.26 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Readers-Writers Problem  Courtois et al 1971  Models access to a database A reader is a thread that needs to look at the database but won’t change it. A writer is a thread that modifies the database  Example: making an airline reservation When you browse to look at flight schedules the web site is acting as a reader on your behalf When you reserve a seat, the web site has to write into the database to make the reservation

6.27 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Readers-Writers Problem  Many threads share an object in memory Some write to it, some only read it Only one writer can be active at a time Any number of readers can be active simultaneously  Key insight: generalizes the critical section concept  One issue we need to settle, to clarify problem statement. Suppose that a writer is active and a mixture of readers and writers now shows up. Who should get in next? Or suppose that a writer is waiting and an endless of stream of readers keeps showing up. Is it fair for them to become active?  We’ll favor a kind of back-and-forth form of fairness: Once a reader is waiting, readers will get in next. If a writer is waiting, one writer will get in next.

6.28 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Readers-Writers Shared variables: Semaphore mutex, wrl; integer rcount; Init: mutex = 1, wrl = 1, rcount = 0; Writer do { P(wrl);... /*writing is performed*/... V(wrl); } while(TRUE); Reader do { P(mutex); rcount++; if (rcount == 1) P(wrl); V(mutex);... /*reading is performed*/... P(mutex); rcount--; if (rcount == 0) V(wrl); V(mutex); } while(TRUE);

6.29 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Readers-Writers Notes  If there is a writer First reader blocks on wrl Other readers block on mutex  Once a reader is active, all readers get to go through Trick question: Which reader gets in first?  The last reader to exit signals a writer If no writer, then readers can continue  If readers and writers waiting on wrl, and writer exits Who gets to go in first?  Why doesn’t a writer need to use mutex ?

6.30 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Does this work as we hoped?  If readers are active, no writer can enter The writers wait doing a P(wrl)  While writer is active, nobody can enter Any other reader or writer will wait  But back-and-forth switching is buggy: Any number of readers can enter in a row Readers can “starve” writers  With semaphores, building a solution that has the desired back-and- forth behavior is really, really tricky! We recommend that you try, but not too hard…

6.31 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Dining-Philosophers Problem  Shared data Bowl of rice (data set), 5 philosophers, 5 chopsticks Each philosopher alternates between thinking and eating Each philosopher needs 2 chopsticks to eat Semaphore chopStick [5] initialized to 1

6.32 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Dining-Philosophers Solution  Philosopher i: do { P(chopstick[i]) P(chopstick[(i+1) % 5]) … eat … V(chopstick[i]); V(chopstick[(i+1) % 5]); … think … } while (1);

6.33 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 One Possible Solution  Introduce state variable enum {thinking, hungry, eating}  Philosopher i can set the variable state[i] only if neighbors not eating: (state[(i+4)%5] != eating) and (state[(i+1)%5] != eating)  Also, need to declare semaphore self, where philosopher i can delay itself.

6.34 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 One Possible Solution Shared: int state[5], semaphore s[5], semaphore mutex; Init: mutex = 1; s[i] = 0, state[i] = thinking, for all i=0.. 4; Philosopher i do { take_chopstick(i); eat(); put_chopstick(i); think(); } while(true); take_chopstick(i) { P(mutex); state[i] = hungry; test(i); V(mutex); P(s[i]); } put_chopstick(i) { P(mutex); state[i] = thinking; test((i+1)%N); test((i-1+N)%N); V(mutex); } test(i) { if(state[i] == hungry && state[(i+1)%N] != eating && state[(i-1+N)%N != eating) { state[i] = eating; V(s[i]); }

6.35 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Synchronization Examples  Solaris  Windows XP  Linux  Pthreads

6.36 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Solaris Synchronization  Implements a variety of locks to support multitasking, multithreading (including real-time threads), and multiprocessing  Uses adaptive mutexes for efficiency when protecting data from short code segments  Uses condition variables and readers-writers locks when longer sections of code need access to data  Uses turnstiles to order the list of threads waiting to acquire either an adaptive mutex or reader-writer lock

6.37 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Windows XP Synchronization  Uses interrupt masks to protect access to global resources on uniprocessor systems  Uses spinlocks on multiprocessor systems  Also provides dispatcher objects which may act as either mutexes and semaphores  Dispatcher objects may also provide events An event acts much like a condition variable

6.38 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Linux Synchronization  Linux: disables interrupts to implement short critical sections (on uniprocessors)  Linux provides: semaphores spin locks

6.39 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Pthreads Synchronization  Pthreads API is OS-independent  It provides: mutex locks condition variables  Non-portable extensions include: read-write locks spin locks

6.40 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Some of the Pthreads calls relating to mutexes. Mutexes in Pthreads (1) Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.41 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Some of the Pthreads calls relating to condition variables. Mutexes in Pthreads (2) Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.42 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Using pthreads to solve the producer-consumer problem. Mutexes in Pthreads (3) Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.43 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Using pthreads to solve the producer-consumer problem. Mutexes in Pthreads (4)... Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6.44 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Using threads to solve the producer-consumer problem. Mutexes in Pthreads (5) Example from Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 End of Chapter 6 (b)