














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































^
^
^ Wakeup
^
^
^ Yield
^
^
^
that follows
that convention
-^ Must control access to it!!!
// Produce char c while (count==n) {no_op} buf[InP] = cInP = InP + 1 mod ncount++} }
thread consumer {
while(1){while (count==0) {
no_op} c = buf[OutP]OutP = OutP + 1 mod ncount-- // Consume char } }
n-1 …
Global variables:
char buf[n]int InP = 0
// place to add
int OutP = 0
// place to get
int count
0 thread consumer { 1
while(1) { 2
while (count==0) { 3
sleep(empty) 4
c = buf[OutP] 6
OutP = OutP + 1 mod n 7
count--; 8
if (count == n-1) 9
wakeup(full) 10
// Consume char 11
while(1) { 2
// Produce char c 3
if (count==n) { 4
sleep(full) 5
buf[InP] = c; 7
InP = InP + 1 mod n 8
count++ 9
if (count == 1) 10
wakeup(empty) 11
n-1 …
Global variables:
char buf[n]int InP = 0
// place to add
int OutP = 0
// place to get
int count
-^ Both threads may sleep forever •^ Buffer contents may be over-written ^ What is this problem called?
-^ Both threads may sleep forever •^ Buffer contents may be over-written ^ What is this problem called?
Race Condition
critical section
mutual
exclusion!