Let S0 be the initial non-negative value of the counting semaphore S.
Each successful P(S) (wait) operation consumes 1 permit from the semaphore.
Each V(S) (signal) operation adds 1 permit to the semaphore.
Total P(S) operations issued = 20.
Total V(S) operations issued = 12.
The maximum possible number of permits available across the entire execution (even under the most favorable ordering where all 12 V(S) operations execute before blocked P(S) operations) is:
Total permits=S0+12 For at least one P(S) operation to remain blocked, the total available permits must not be enough to satisfy all 20 P(S) operations:
S0+12<20⟹S0<8 Since S0 must be an integer, the largest possible initial value is:
With S0=7, at most 7+12=19 P(S) operations can succeed, guaranteeing that at least 1 P(S) operation remains blocked [CS-2, Q49].