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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?
  • 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 and T initially 1
  • c)
    P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1
  • d)
    V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1
Correct answer is option 'C'. 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’. The definition of these functions are : 
Wait(S) {
       while (i <= 0) ;
       S-- ;
}
Signal(S) {
       S++ ;
}
 
Initially S = 1 and T = 0 to support mutual exclusion in process ‘P’ and ‘Q’. 
Since, S = 1 , process ‘P’ will be executed and function Wait(S) will decrement the value of ‘S’. So, S = 0 now. 
Simultaneously, in process ‘Q’ , 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 function V(T). 
While the control is in process ‘Q’, S = 0 and process ‘P’ will be stuck in while loop. Process ‘P’ will not execute till the time process ‘Q’ prints ‘11’ and makes S = 1 by calling function V(S). 
 
Thus, process 'P' and 'Q' will keep on repeating to give the output ‘00110011 …… ‘ . 
 
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:

Process P:
- The process P prints "00" indefinitely.

Process Q:
- The process Q prints "11" indefinitely.

Objective:
- To ensure that the output string never contains a substring of the form "01n0" or "10n1" where n is odd.

Explanation of Option C:
- P(S) at W: Process P acquires semaphore S at point W.
- V(S) at X: Process P releases semaphore S at point X.
- P(S) at Y: Process Q acquires semaphore S at point Y.
- V(S) at Z: Process Q releases semaphore S at point Z.
- S initially set to 1: Semaphore S is initialized to 1.

Explanation of Correctness:
- By using semaphore S to synchronize the processes at critical points, we ensure that the processes do not print "01n0" or "10n1" where n is odd.
- Process P and Process Q alternate access to semaphore S, ensuring mutual exclusion between the two processes.

Conclusion:
- Option C is the correct choice as it correctly synchronizes the processes P and Q using semaphore S to prevent the occurrence of unwanted substrings in the output.
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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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 ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?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 and T initially 1c)P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1d)V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1Correct answer is option 'C'. 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