Please help !!! i have no i dea how to solve it :( A synchronization mechanism c
ID: 3820767 • Letter: P
Question
Please help !!! i have no i dea how to solve it :(
A synchronization mechanism consists of 2 atomic routines, ENQ(r) and DEQ(r). "r" is a resource variable that has two fields, inuse (boolean) and queue (a queue) which is a queue of processes waiting to acquire the resource. The definitions of ENQ and DEQ are: ENQ(r): if (r.inuse = =1) then begin insert current process in r.queue block end else r.inuse = 1; DEQ(r): if r.queue = nil then inuse = false else delete a process from r.queue and activate it. Construct an implementation of ENQ/DEQ using semaphores. You can use other variables, etc that you need, but no other atomic code or synchronization constructs other than P or V can be used. Do the reverse of Q3, that is implement Semaphores using ENQ/DEQ.Explanation / Answer
Q3.
ENQ(r):
P(r)
if(r.inuse==1) then begin
Insert current process in r.queue
V(r)
Block
End
Else
P(r )
r.inuse=1;
V(r )
DEQ(r):
P( r)
if r.queue=nil then inuse=false
V(r )
Else
P(r )
delete a process from r.queue and activate it.
V( r)
Q4.
P (r)
If(r.inuse==1) then begin
ENQ( r)
Block
End
V( r)
If(r.queue=nil then inuse=false
Else
DEQ( r)