Similar questions 1 more →
Synchronization & Concurrency




Answer & solution
Answer: B, with generation-entry qualification (no official key was published)
1. The intended repair is to prevent a process from incrementing the next generation’s arrival count until the previous generation has reset process_arrived to zero, corresponding to B. It must wait before acquiring S, leaving S available to the final departing process that performs the reset.
2. A lets an early departure lower process_arrived while others still need to observe 3; C prevents necessary scheduling on a uniprocessor; D prevents the shared departure count reaching 3. However the phrase first process to enter is a conceptual generation gate, not complete executable synchronization.
3. Merely adding an unconditional while(process_arrived!=0) to every invocation blocks the second arrival of the same generation; waiting only one vaguely designated process while allowing another new-generation entrant through is also insufficient. A concrete reusable barrier needs a correctly synchronized generation flag or two-turnstile design.
4. Teaching check: Waiting while holding S would prevent the final departing process from acquiring S to reset the counters. Waiting must therefore occur outside that critical section, and it must distinguish generations correctly. A two-turnstile or generation-counter barrier is a concrete way to enforce this separation.