









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Hollingsworth; Class: Operating Systems; Subject: Computer Science; University: University of Maryland; Term: Spring 2004;
Typology: Study notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!










z^
z^
Process 1
Process 2 Shared Region
z^
z^
z^
Counter Decrement
reg
= counter 1
reg
= counter 2
reg
= reg 1
reg
= reg 2
counter = reg
1
counter = reg
2
z^
0
producer
reg
= counter 1
{ reg
producer
reg
= reg 1
{ reg
consumer
reg
= counter 2
{ reg
consumer
reg
= reg 2
{ reg
producer
counter = reg
1
{ counter = 6 }
consumer
counter = reg
2
{ counter = 4 }
Thisshouldbe 5!
z^
result produced
z^
z^
uses
shared data
z^
May assume that some instructions are atomic–
typically load, store, and test word instructions z^
Algorithm #1 for two processes–
use a shared variable that is either 0 or 1– when P
= k a process may enter the regionk
repeat (while turn != 0);// critical sectionturn = 1;// non-critical section until false;
repeat (while turn != 1);// critical sectionturn = 0;// non-critical section until false;
in the critical section stops process 1.
z^
bool flag[2];repeat flag[i] = true;while (flag[j]);// critical sectionflag[i] = false;// non-critical section until false;
z^
z^
z^
bool choosing[n];integer number[n];choosing[i] = true;number[i] = max(number[0],..number[n-1])+1;choosing[i] = false;for j = 0 to n-
while choosing[j];while number[j] != 0 and ((number[j], j) < number[i],i); end// critical sectionnumber[i] = 0
z^
possible• it requires a critical section!
process id
z^
z^
while test-and-set(lock);// critical sectionlock = false;// non-critical section until false; z^
bounded waiting time version repeat
waiting[i] = true;key = true;while waiting[i] and key
key = test-and-set(lock); waiting[i] = false;// critical sectionj = (i + 1) % nwhile (j != i) and (!waiting[j])
j = (j + 1) % n; if (j == i)
lock = false; else
waiting[j] = false; // non-critical section until false;
Note: no priority based on wait time no process waitingrelease process j
look for a waiting process wait until released or no one busy
z^
z^
z^
z^
z^
z^
z^
signal operations
z^
value: integer = 1;L: FIFO list of process; end; z^
S.value = S.value -1if S.value < 0 then {
add this process to S.Lblock;
};
z^
S.value = S.value+1if S.value <= 0 then {
remove process P from S.Lwakeup(P);
}
Can be neg, if so, indicateshow many waiting
Bounded waiting!!