The Gateway to Computer Science Excellence
0 votes
32 views
Consider a process with three threads A, B, and C. The default thread of the process receives multiple requests, and places them in a request queue that is accessible by all the three threads A, B, and C. For each request, we require that the request must first be processed by thread A, then B, then C, then B again, and finally by A before it can be removed and discarded from the queue. Thread A must read the next request from the queue only after it is finished with all the above steps of the previous one.
sem a1done = 0; b1done = 0; cdone = 0; b2done = 0;
ThreadA:
get request from queue and process
up(a1done)
down(b2 done)
finish with request
Thread B:
down(a1done)
//do work
up(b1done)
down(cdone)
//do work
up(b2done)
ThreadC:
down(b1done)
//do work
up(cdone)
All thread is running in forever loop.
Which of the following is correct?

A. The proposed solution prevents deadlock but fails to guarantee mutual exclusion

B.The proposed solution guarantees mutual exclusion but fails to prevent deadlock

C.The proposed solution guarantees mutual exclusion and prevents deadlock
in Operating System by (43 points) | 32 views

1 Answer

+1 vote
Best answer
is C the answer?
by (481 points)
selected by
0
How answer is C.
+1

@Shashankesh Upadhyay

Given code is :

A v(adone) p(b2done)

p(adone) B v(b1done) p(cdone) v(b2done)

p(b1done) C v(cdone)

Initially all the four semaphores are initialised to zero.

If we carefully observe it follows sequential order same as mentioned in the problem.

B cannot start execution before A because it performs down operation on adone and blocks then A will perform up on adone and wake up B after its execution and A performs down on b2done as a result A will be blocked which will be again woke up by B when it completes second time execution.

Same goes with C it cannot start execution unless A and B completes their first round.

So mutual exclusion is Guaranteed.

I think there is no way that they will be in deadlock.

Btw what is the answer given ??

 

0
Yeah of course it's C. Thank you for your generous elaborated explanation, it helped me a lot.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,654 questions
56,169 answers
193,878 comments
94,301 users