



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!




CMSC 412^1
repeat while test-and-set(lock); // critical section lock = false; // non-critical section until false; l bounded waiting time version repeat waiting[i] = true; key = true; while waiting[i] and key key = test-and-set(lock); waiting[i] = false; // critical section j = (i + 1) % n while (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 waiting release process j look for a waiting process wait until released or no one busy CMSC 412^2
l getting critical section problem correct is difficult
CMSC 412^3
l critical section repeat P(mutex); // critical section V(mutex); // non-critical section until false; l Require that Process 2 begin statement S2 after Process 1 has completed statement S1: Process 2 S V(synch) Process 1 P(synch) S CMSC 412^4
CMSC 412^7
reader() { repeat P(x); readcount = readcount + 1; if readcount = 1 then P (wsem); V(x); READUNIT; P(x); readcount = readcount - 1; if readcount = 0 V(wsem); V(x); forever }; writer() { repeat P(wsem); WRITEUNIT; V(wsem) forever } CMSC 412^8
CMSC 412^9
repeat P(z); P(rsem); P(x); readcount++; if (readcount == 1) then P(wsem); V(x); V(rsem); V(z); readunit; P(x); readcount- -; if readcount == 0 then V (wsem) V(x) forever
repeat P(y); writecount++: if writecount == 1 then P(rsem); V(y); P(wsem); writeunit V(wsem); P(y); writecount--; if (writecount == 0) then V(rsem); V(y); forever; CMSC 412^10
P(z); P(rsem); P(x); readcount++; if (readcount==1) then P(wsem); V(x); V(rsem); V(z);