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:
}
 
Q. 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. 
 
Please comment below if you find anything wrong in the above post.
View all questions of this test
Most Upvoted Answer
Suppose we want to synchronize two concurrent processes P and Q using ...
Explanation:

To achieve synchronization between processes P and Q, we need to ensure that they perform their operations in a mutually exclusive manner. In other words, while one process is executing its critical section, the other process must wait to execute its critical section.

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.

Let's see how this option ensures synchronization:

- P(S) at W: Process P acquires semaphore S before entering its critical section.
- V(T) at X: Process P releases semaphore T after exiting its critical section. This allows process Q to enter its critical section.
- P(T) at Y: Process Q acquires semaphore T before entering its critical section.
- V(S) at Z: Process Q releases semaphore S after exiting its critical section. This allows process P to re-enter its critical section.

Thus, the processes alternate in accessing their critical sections in a mutually exclusive manner. And the output will start with 001100110011 because:

- Process P prints 0, 0 in its critical section.
- Process Q prints 1, 1 in its critical section.

Therefore, option B is the correct answer.

Note: The other options either do not ensure mutual exclusion or violate the given initial conditions.
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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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:}Q.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