Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Suppose we want to synchronize two concurrent... Start Learning for Free
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
Process P:
while (1) {
W:
   print '0';
   print '0';
X:
}
    
Process Q:
while (1) {
Y:
   print '1';
   print '1';
Z:
}
Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with '001100110011' ?
  • a)
    P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
  • b)
    P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0
  • c)
    P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
  • d)
    P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Suppose we want to synchronize two concurrent processes P and Q using ...
P(S) means wait on semaphore ‘S’ and V(S) means signal on semaphore ‘S’. [sourcecode] Wait(S) { while (i <= 0) --S; } Signal(S) { S++; } [/sourcecode] Initially, we assume S = 1 and T = 0 to support mutual exclusion in process P and Q. Since S = 1, only process P will be executed and wait(S) will decrement the value of S. Therefore, S = 0. At the same instant, in process Q, value of T = 0. Therefore, in process Q, control will be stuck in while loop till the time process P prints 00 and increments the value of T by calling the function V(T). While the control is in process Q, semaphore S = 0 and process P would be stuck in while loop and would not execute till the time process Q prints 11 and makes the value of S = 1 by calling the function V(S). This whole process will repeat to give the output 00 11 00 11 … .
 
Thus, B is the correct choice.
View all questions of this test
Most Upvoted Answer
Suppose we want to synchronize two concurrent processes P and Q using ...
Explanation:

The given code consists of two concurrent processes, P and Q, which run indefinitely. Process P prints "00" and process Q prints "11" repeatedly. We need to synchronize these processes using binary semaphores S and T in such a way that the output always starts with "001100110011".

Let's analyze the options one by one:

Option A:
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1

- In this option, process P acquires semaphore S at point W and releases it at point X. Similarly, process Q acquires semaphore T at point Y and releases it at point Z.
- Initially, both semaphores S and T are set to 1.
- Since both processes can acquire their respective semaphores at any time, the order of execution is not guaranteed.
- Therefore, this option does not ensure that the output will always start with "001100110011".

Option B:
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0

- In this option, process P acquires semaphore S at point W and releases semaphore T at point X. Similarly, process Q acquires semaphore T at point Y and releases semaphore S at point Z.
- Initially, semaphore S is set to 1 and semaphore T is set to 0.
- The semaphore T being initially 0 ensures that process Q will always wait at point Y until it is released by process P at point X. This guarantees that process P always executes first.
- Therefore, this option ensures that the output will always start with "001100110011".

Option C:
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1

- This option is similar to option A, where both processes can acquire their respective semaphores at any time.
- Therefore, this option does not ensure that the output will always start with "001100110011".

Option D:
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0

- In this option, process P acquires semaphore S at point W and releases it at point X. Similarly, process Q acquires semaphore T at point Y and releases it at point Z.
- Initially, semaphore S is set to 1 and semaphore T is set to 0.
- Since process P releases semaphore S before process Q can acquire it, there is no synchronization between the processes. Therefore, the output can start with either "00" or "11".
- Therefore, this option does not ensure that the output will always start with "001100110011".

Hence, the correct option is B.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer?
Question Description
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. 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 Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. 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 Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer?.
Solutions for Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. 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 Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.Process P:while (1) {W: print 0; print 0;X:} Process Q:while (1) {Y: print 1; print 1;Z:}Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with 001100110011 ?a)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1b)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0c)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1d)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0Correct answer is option 'B'. 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