









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!










!"#
$
'
Concurrent process execution can be:
Interleaved
Physically simultaneous
' &
Process, thread, or task
Granularity
(
(
Precedence Graphs must
be ACYCLIC
What does the following graph represent?
S2 must be performed before S3 begins
AND
S3 must be performed before S2 begins
) *
These are called the Bernstein Conditions.
+ !"#
+ !"#
.
4 5
6 78 #
0
monitor reader_writer_2{ int numberOfReaders = 0; boolean busy = false ; condition okToRead, okToWrite; public : startRead(){ if (busy || okToWrite.queue) okToRead.wait; numberOfReaders = numberOfReaders+1; okToRead.signal; } finishRead() { numberOfReaders = numberOfReaders-1; if (numberOfReaders =0) okToWrite.signal; } startWrite(){ if (busy || numberOfReaders != 0) okToWrite.wait; busy = true ; } finishWrite() { busy = false ; if (okToWrite.queue) okToWrite.signal; else okToRead.signal; } }
' 1 #
' 1 #
0
enum status {eating, hungry, thinking}; monitor diningPhilosophers{ status state[N]; condition self[N]; int j; // This procedure can only be called from within the monitor test( int i) { if((state[i-1 MOD N] != eating) && (state[i] == hungry) && (state[i+1 MOD N] != eating) ) { state[i] = eating; self[i].signal; } public : pickUpForks(){ state[i] = hungry; test(i); if (state[i] != eating) self[i].wait; } putDownForks(){ state[i] = thinking; test(i-1 MOD N); test(i+1 MOD N); } diningPhilosophers() { // Monitor initialization code for ( int i=0; i<N; i++) state[i] = thinking; } }
monitor ringBufferMonitor;
var ringBuffer: array [0..slots-1] of stuff;
slotInUse: 0..slots; nextSlotToFill: 0..slots-1; nextSlotToEmpty: 0..slots-1;
ringBufferHasData, ringBufferHasSpace: condition ;
procedure fillASlot(slotData: stuff);
begin
if (slotInUse = slots) then wait(ringBufferHasSpace); ringBuffer[nextSlotToFill] := slotData; slotInUse := slotInUse + 1; nextSlotToFill := (nextSlotToFill+1) MOD slots;
signal(ringBufferHasData);
end ;