Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider two processes P1 and P2 accessing th... Start Learning for Free
Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :
While true do {
     L1 : ................
     L2 : ................
     X = X + 1;
     Y = Y - 1;
     V(SX);
     V(SY);
}
P2 :
While true do {
L3 : ................
L4 : ................
Y = Y + 1;
X = Y - 1;
V(SY);
V(SX);
}
 
Q. In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively
  • a)
    P(SY), P(SX); P(SX), P(SY)
  • b)
    P(SX), P(SY); P(SY), P(SX)
  • c)
    P(SX), P(SX); P(SY), P(SY)
  • d)
    P(SX), P(SY); P(SX), P(SY)
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
Consider two processes P1 and P2 accessing the shared variables X and ...
Option A: In line L1 (p(Sy)) i.e. process p1 wants lock on Sy that is held by process p2 and line L3 (p(Sx)) p2 wants lock on Sx which held by p1. So here circular and wait condition exist means deadlock.
Option B : In line L1 (p(Sx)) i.e. process p1 wants lock on Sx that is held by process p2 and line L3 (p(Sy)) p2 wants lock on Sx which held by p1. So here circular and wait condition exist means deadlock.
Option C: In line L1 (p(Sx)) i.e. process p1 wants lock on Sx and line L3 (p(Sy)) p2 wants lock on Sx . But Sx and Sy can’t be released by its processes p1 and p2.
Please read the following to learn more about process synchronization and semaphores: Process Synchronization Set 1
View all questions of this test
Most Upvoted Answer
Consider two processes P1 and P2 accessing the shared variables X and ...
Explanation:
To avoid deadlock, the two processes must acquire the same set of semaphores in the same order. In this case, both processes need to acquire SX and SY in the same order.

At L1 in P1, P(SX) is needed to acquire the semaphore SX.
At L2 in P1, P(SY) is needed to acquire the semaphore SY.
At L3 in P2, P(SY) is needed to acquire the semaphore SY.
At L4 in P2, P(SX) is needed to acquire the semaphore SX.

So, the correct operators at L1, L2, L3, and L4 are P(SX), P(SY); P(SX), P(SY).

Therefore, option 'D' is the correct answer.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer?
Question Description
Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual semaphone operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :While true do { L1 : ................ L2 : ................ X = X + 1; Y = Y - 1; V(SX); V(SY);}P2 :While true do {L3 : ................L4 : ................Y = Y + 1;X = Y - 1;V(SY);V(SX);}Q.In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectivelya)P(SY), P(SX); P(SX), P(SY)b)P(SX), P(SY); P(SY), P(SX)c)P(SX), P(SX); P(SY), P(SY)d)P(SX), P(SY); P(SX), P(SY)Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev