GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Trace and repair overlapping barrier generations

2 questions solved the same way, newest first. Back to Operating Systems

How these are solved

These linked questions use the same three-process barrier and the same procedure: trace a fast process entering the next invocation before the prior generation has completed/reset its shared arrival and departure counters, then test whether proposed changes prevent that interleaving.

2 marks · MCQ
Report issue

Reusable barrier generation race

Synchronization & Concurrency

Question 78, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Why is the implementation incorrect?
Options:
(A) The use of binary semaphore S makes it wrong
(B) Two consecutive barrier invocations can deadlock
(C) Lines 6–10 do not need a critical section
(D) It is correct with two processes instead of three
Question 78, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Why is the implementation incorrect?
Options:
(A) The use of binary semaphore S makes it wrong
(B) Two consecutive barrier invocations can deadlock
(C) Lines 6–10 do not need a critical section
(D) It is correct with two processes instead of three
Question 78, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Why is the implementation incorrect?
Options:
(A) The use of binary semaphore S makes it wrong
(B) Two consecutive barrier invocations can deadlock
(C) Lines 6–10 do not need a critical section
(D) It is correct with two processes instead of three
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Once all three arrive, process_arrived=3. Let P leave the first barrier, increment process_left to 1, and immediately enter its next barrier before Q and R have finished the first.

2. It increments process_arrived to 4. If Q and R have not passed the first barrier’s while test, they now wait for process_arrived==3, and P also waits in its second invocation.

3. No one can perform the final reset: deadlock. Binary semaphores correctly protect the updates and are not the cause; the missing separation between barrier generations is.

4. The same issue can occur with two processes. Hence B.

5. Teaching check: The first invocation opens when arrival count reaches three, but the code does not close entry to the next generation. An early returning process can raise the count to four while another still tests for equality with three. A protected increment alone does not prevent mixing generations.

Original paper, page 12

2 marks · MCQ
Report issue

Preventing overlap of barrier generations

Synchronization & Concurrency

Question 79, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Which proposed repair addresses its reuse problem? The phrase “first process” in B is only a conceptual generation gate and needs a concrete synchronization implementation.
Options:
(A) Replace lines 6–10 by process_arrived--
(B) At barrier entry, the first process waits for process_arrived to become zero before executing P(S)
(C) Disable context switching throughout the barrier
(D) Make process_left private instead of shared
Question 79, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Which proposed repair addresses its reuse problem? The phrase “first process” in B is only a conceptual generation gate and needs a concrete synchronization implementation.
Options:
(A) Replace lines 6–10 by process_arrived--
(B) At barrier entry, the first process waits for process_arrived to become zero before executing P(S)
(C) Disable context switching throughout the barrier
(D) Make process_left private instead of shared
Question 79, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Which proposed repair addresses its reuse problem? The phrase “first process” in B is only a conceptual generation gate and needs a concrete synchronization implementation.
Options:
(A) Replace lines 6–10 by process_arrived--
(B) At barrier entry, the first process waits for process_arrived to become zero before executing P(S)
(C) Disable context switching throughout the barrier
(D) Make process_left private instead of shared
Question 79, GATE 2006: Three processes repeatedly synchronize at a barrier. Shared process_arrived and process_left start at 0. S is a binary semaphore, initially available; P acquires and V releases it. Each process calls:
void barrier(void) {
 1: P(S);
 2: process_arrived++;
 3: V(S);
 4: while (process_arrived != 3);
 5: P(S);
 6: process_left++;
 7: if (process_left == 3) {
 8:   process_arrived=0;
 9:   process_left=0;
10: }
11: V(S);
}
Use the intended shared-memory pseudocode model, not a claim of data-race-safe modern C. Which proposed repair addresses its reuse problem? The phrase “first process” in B is only a conceptual generation gate and needs a concrete synchronization implementation.
Options:
(A) Replace lines 6–10 by process_arrived--
(B) At barrier entry, the first process waits for process_arrived to become zero before executing P(S)
(C) Disable context switching throughout the barrier
(D) Make process_left private instead of shared
Tap to enlarge
Your answer
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.

Original paper, page 12