A synchronization mechanism consists of 2atomic routines, ENQ(r) and DEQ(r). \"r
ID: 3812247 • Letter: A
Question
A synchronization mechanism consists of 2atomic 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
Enqueue(p, item)
{
Acquire(mutex);
put item into p;
Release(mutex);
}
DEQ
Dequeue(q)
{
Acquire(mutex);
take an item from p;
Release(mutex);
return item;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.