3 3 votes Consider program for P1 and P2: Here, m and n are binary semaphore variables whose values are initially initialized to 1. x and y are shared resources whose values are initialized to 0. Which of the following holds by above processes? A :- Deadlock and no mutual exclusion B :-Deadlock and race condition C :-No deadlocks and no race condition D:- Race condition and no deadlock Operating System made-easy-test-series operating-system semaphore deadlock-prevention-avoidance-detection mutual-exclusion + – rahul sharma 5 4.2k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments rahul sharma 5 commented Dec 18, 2017 reply Follow flag Yeah .They said that x and y are shared resources.So it means x and y are accessed it critical section. And now both of them can enter critical section at same time(one will use x and other will use y ,but both are entering in critical section.).Hence ME not satisfied.This is what they told. But i dont know if this is a valid assumption.What if x and y has separate critical section entry exit code?I am not sure if this is a valid case though 0 0 replyShare Ashwin Kulkarni commented Dec 18, 2017 reply Follow flag Yes I also assumed x and y will have separate CS. So here doubt arises that all shared variables will be accessed in the same CS? 0 0 replyShare rahul sharma 5 commented Dec 18, 2017 reply Follow flag Not sure;I have the same doubt.Lets wait.Someone will solve this doubt:) 0 0 replyShare Please log in or register to add a comment.
1 1 vote P1() 1.wait(m) 2.x++ context switch P2() 1.wait(n) 2.y++ 3.wait(m) // waiting for m to became 1 context switch P1() // arraive again 3.wait(n)// waitning for n to become 1 1.conclusion – it create deadlock 2.conclusion – there is mutual exclusion ANS – option B indra kumar sahu answered Oct 18, 2020 indra kumar sahu comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes P1 will execute wait(m) & P2 will execute wait(n) so both m & n will become 0. So when P1 will execute wait(n) & P2 will execute wait(m). They both will go to deadlock. Here, no mutual exclusion took place. Manikant Sharma 6 answered Dec 19, 2017 Manikant Sharma 6 comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments prithvish111 commented Oct 17, 2020 reply Follow flag Mutual Exclusion : At least one resource must be held in a non sharable mode; that is, only one process at a time can use the resource. If another process requests that resource, the requesting process must be delayed until the resource has been released. you are right, but here the problem is with semaphores, can you explain why mutual exclusion is not achieved here? 0 0 replyShare indra kumar sahu commented Oct 17, 2020 i edited by indra kumar sahu Oct 18, 2020 reply Follow flag above ans is correct for deadlock but there is mutual exclusion for sure☺ 2 2 replyShare sachin486 commented Oct 21, 2020 reply Follow flag there is no relation of mutual exclusion and semaphores. as u said in mutual exclusion resource cant be shared here that resource is some lines of code known as critical section and i didn’t said that mutual exclusion is not achived here...there is mutual exclusion and thats also posiblity of dead lock which in this case has occured 0 0 replyShare Please log in or register to add a comment.
0 0 votes The answer should be Deadlock and no race condition. The given options do not match the answer. There exists a deadlock scenario namely P1 and P2 both execute, both acquire m and n respectively. Both execute their respective increment statements and then both execute the wait statements trying to acquire each others acquired semaphores which creates a deadlock scenario. There does not exist a Race condition since there is no scenario in which both P1 and P2 can execute increments of the same variable i.e x or y at the same time. AngshukN answered Dec 19, 2021 AngshukN comment Share Follow See 1 comment 1 1 comment reply the_bob commented Jan 22, 2022 reply Follow flag This is the correct answer, since in case of mutual exclusion, we need the condition that 2 or more threads are trying to modify the same shared location at the same time! 0 0 replyShare Please log in or register to add a comment.