















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!
















1
Slides derived from material in “Operating System Concepts,” by Silberschatz, Galvin, and Gagne
3
#define BUFFER_SIZE 10 typedef struct {
... } item; item buffer[BUFFER_SIZE]; int counter = 0;
7
Critical section for n processes
boolean choosing[n]; int number[n];
9
do { choosing[i] = true; number[i] = max(number[0], number[1], …, number [n – 1])+1; choosing[i] = false; for (j = 0; j < n; j++) { while (choosing[j]) ; while ((number[j] != 0) && (number[j,j] < number[i,i])) ; } critical section number[i] = 0; remainder section } while (1);
boolean TestAndSet(boolean &target) { boolean rv = target; tqrget = true;
return rv; }
13
15
semaphore mutex; //initially mutex = 1
19
21
25
do { … produce an item in nextp … wait(empty); wait(mutex); … add nextp to buffer … signal(mutex); signal(full); } while (1);
do { wait(full) wait(mutex); … remove an item from buffer to nextc … signal(mutex); signal(empty); … consume the item in nextc … } while (1);
27
semaphore mutex, wrt;
Initially
mutex = 1, wrt = 1, readcount = 0
wait(wrt); … writing is performed … signal(wrt);
31
v: shared T
region v when B do S
where B is a boolean expression.
33
struct buffer { int pool[n]; int count, in, out; }
37
39