Synchronization & Concurrency

Answer & solution
Official answer: C
With binary semaphore1 the updates are mutually exclusive: V1=10+5−3=12. With counting semaphore2, two updates may overlap. For a witness to V2=7, let one decrement enter and read 10, then pause before its write. Through the second permit run all five increments to completion. Resume the held decrement to overwrite X with 9, then run the other two decrements serially, giving 8 then 7. No value below 7 can arise because a value’s chain of read/write dependencies starts at 10 and contains at most the three decrement operations; increments only increase it. Thus12, 7, option C, under the intended non-atomic read-modify-write interleaving model.
Teaching detail. A semaphore with capacity two limits concurrency but does not make each arithmetic assignment atomic. Two threads can read the same old value and later overwrite each other's results. The witness yielding 7 uses only two simultaneous entrants at any moment: one delayed decrement occupies one permit while all other selected operations use the second. The lower-bound argument follows the ancestry of the final written value, not the total number of writes. Each decrement in that ancestry contributes −1 once at most, and there are only three decrements available.
