Operating Systems Semaphores, Condition Variables, and Monitors
Lecture 6 Michael O’Boyle
1
Operating Systems Semaphores, Condition Variables, and Monitors - - PowerPoint PPT Presentation
Operating Systems Semaphores, Condition Variables, and Monitors Lecture 6 Michael OBoyle 1 Semaphore More sophisticated Synchronization mechanism Semaphore S integer variable Can only be accessed via two indivisible
1
5
6
7
8
9
10
11
12
13
14 var mutex: lock ; mutual exclusion to shared data freeslot: condition ; there’s a free slot fullslot: condition ; there’s a full slot producer: lock(mutex) ; get access to pointers if [no slots available] wait(freeslot); <add item to slot, adjust pointers> signal(fullslot); unlock(mutex) consumer: lock(mutex) ; get access to pointers if [no slots have data] wait(fullslot); <remove item from slot, adjust pointers> signal(freeslot); unlock(mutex); <use the item>
15
16
17
18
19
Proc A Proc B Proc C
20
21
P P C C
22
P P C P
23
24
25
P P C P
26
P P C P
Queue of threads waiting for condition “not full” to be signaled
27
28
29