






















































































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!























































































oldIntStat: intoldIntStat = SetInterruptsTo (DISABLED)if mutex == 0mutex = 1heldBy = currentThreadoldIntStat = SetInterruptsTo (oldIntStat)elsesleepThreads.AddToEnd(currentThread)currentThread.Sleep()oldIntStat = SetInterruptsTo (oldIntStat)endIf endMethod
method Unlock ()var
oldIntStat: intt: ptr to ThreadoldIntStat = SetInterruptsTo (DISABLED)mutex = 0if sleepThreads.IsEmpty() == false
t = sleepThreads.Remove()t.status = READYreadyList.AddToEnd(t) endIfoldIntStat = SetInterruptsTo (oldIntStat) endMethod
^
^
^
^
^
^
var c, em: charwhile true
Receive(producer, &c)
-- Wait for a char
Send(producer, &em)
-- Send empty message back
// Consume char... const N = 100^ endWhileend
-- Size of message buffer
var em: charfor i = 1 to N
-- Get things started by
Send (producer, &em)
sending N empty messages
endFor
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
^
if and only if the following
^
^
^
acquire (resource_1) use resource_1 release (resource_1)
r1_sem: Semaphore
acquire (resource_2) use resource_2 release (resource_2)
acquire (resource_1) use resource_1 release (resource_1)
acquire (resource_1) acquire (resource_2) use resources 1 & 2 release (resource_2) release (resource_1)
acquire (resource_1) acquire (resource_2) use resources 1 & 2 release (resource_2) release (resource_1)
acquire (resource_1) acquire (resource_2) use resources 1 & 2 release (resource_2) release (resource_1)
acquire (resource_1) acquire (resource_2) use resources 1 & 2 release (resource_2) release (resource_1)
No deadlock can occur here!