in Operating System
381 views
0 votes
0 votes
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
381 views

1 Answer

1 vote
1 vote
Best answer
is C the answer?
selected by

3 Comments

How answer is C.
0
0

@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 ??

 

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

Related questions