GATEverse
← GATE CSE 2021 Set 1

Q46

MSQ2 marks

Consider the following pseudocode, where S\textsf{S} is a semaphore initialized to 55 in line #2\#2 and counter\textsf{counter} is a shared variable initialized to 00 in line #1\#1. Assume that the increment operation in line #7\#7 is not\textit{not} atomic. 1. int counter = 0; 2. Semaphore S = init(5); 3. void parop(void) 4. { 5. wait(S); 6. wait(S); 7. counter++; 8. signal(S); 9. signal(S); 10. } If five threads execute the function parop\textsf{parop} concurrently, which of the following program behavior(s) is/are possible?

Sign in to save attempts.

Loading…