Pseudocode of P1, P2, and P3

Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?
Correct : a,b,c
All three processes run the same code. A = 1, B = 0, X = 0 initially.
How it flows
Only one process can pass Wait(A) at a time since A is binary. The 1st process prints , makes X = 1, skips the if-block, calls Signal(A), then blocks at Wait(B) since B = 0.
The 2nd process prints , makes X = 2, enters the if-block, prints $, calls Signal(B) which unblocks the 1st process, then calls Signal(A).
The 1st process now prints # and calls Signal(B). The 3rd process prints *, makes X = 3, skips the if-block, then waits on B and eventually prints #.
Why D is impossible
D requires three * prints before .Butthe3rdprocesscannotenteruntilthe2ndcallsSignal(A),whichhappensonlyafter. But the 3rd process cannot enter until the 2nd calls Signal(A), which happens only after
.Butthe3rdprocesscannotenteruntilthe2ndcallsSignal(A),whichhappensonlyafter is already printed. So ***$ can never happen.
Why A, B, C are possible
The 3rd process's * can appear before the first #, between the two # prints, or after both — depending on scheduling. All three give valid distinct patterns, making A, B, and C all possible.
Correct answer: A, B, C ✓
Similar Questions
Total Unique Visitors