Computer Science OS Question: A synchronization mechanism consists of 2 atomic r
ID: 3696149 • Letter: C
Question
Computer Science OS Question:
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.
NOW, do the reverse of this question and implement Semaphores using ENQ/DEQ.
SHOW ALL WORK/EXPLAIN PLEASE.
Explanation / Answer
A synchronization mechanism in operating systems means that the resources of the system are shared by the concurrent processes such that the consistency of the data is maintained.
The problems like critical section problem, synchronization hardware, mutex locks, semaphores.
Here, the synchronization mechanism has two 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 given in the question.
The implementation of ENQ/DEQ using semaphores is as follows:
ENQUEUE:
ENQ (r, item)
{
acquire(mutex);
put the item into the queue of the variable r;
release(mutex);
}
DEQUEUE:
DEQ(r)
{
acquire(mutex);
pick up an item from the queue of the variable r.
release(mutex);
return item;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.