📝 The Critical Section Problem in Process Synchronization (36 MCQs)
Protecting Shared Data During Critical-Section Execution
The critical-section problem concerns designing a protocol that controls access to shared data when multiple processes execute concurrently. Each process contains a critical section where it accesses or modifies shared resources, together with entry and exit sections. The synchronization protocol determines which process may enter, preventing conflicting operations while allowing independent processes to continue performing noncritical work.
Why Uncontrolled Entry Produces Inconsistent Results
Concurrent execution allows instructions from different processes to interleave in unpredictable orders. If two processes update the same shared variable simultaneously, one update may overwrite the other. A correct protocol must coordinate entry without unnecessarily preventing progress or allowing one process to wait indefinitely while others repeatedly enter.
Entry, Critical, Exit, and Remainder Sections
A process first executes its entry section to request permission to access protected data. After receiving permission, it executes the critical section and then performs its exit section to release access. It subsequently executes its remainder section independently. The protocol must enforce mutual exclusion, progress, and bounded waiting under its stated execution assumptions.
Preventing Lost Updates in a Shared Balance
Suppose two processes withdraw 100 units from a shared balance of 1,000. Without protection, both may read 1,000 and independently write 900, losing one withdrawal. A critical-section protocol ensures that the first process completes its update before the second reads the balance, producing the correct final balance of 800.
Fairness, Safety, and Processor Utilisation
Critical-section protection maintains consistency in shared counters, process tables, kernel structures, and database records. Mutual exclusion prevents overlapping protected operations, while progress and bounded waiting address coordination and fairness. However, long critical sections reduce concurrency, busy waiting wastes processor cycles, and poorly designed protocols can introduce deadlocks or starvation.
Misconceptions About Critical-Section Correctness
'Mutual exclusion alone guarantees a correct protocol' is incorrect because progress and bounded waiting also matter. 'A process must always enter the critical section eventually' is incorrect because eligibility depends on protocol conditions. 'The remainder section requires mutual exclusion' is incorrect because it contains operations outside the protected region.
Exam Focus: Testing the Three Critical-Section Conditions
Identify the entry, critical, exit, and remainder sections in a concurrent program. Evaluate a proposed solution against mutual exclusion, progress, and bounded waiting separately. Questions may present execution traces, shared-variable updates, or pseudocode and ask whether two processes can enter simultaneously, whether selection can proceed, or whether waiting is bounded.
Key Terms of the Critical-Section Problem
- Entry section - Requests permission to enter.
- Exit section - Releases protected access.
- Critical section - Performs shared-resource operations.
- Remainder section - Executes unrelated process work.
- Mutual exclusion - Allows one protected entrant.
- Bounded waiting - Restricts indefinite postponement.
📝 All The Critical Section Problem in Process Synchronization MCQs
Q1. [Process structure] A process repeatedly performs shared-data work. Which order correctly places the request for permission, protected work, release of permission, and unrelated computation?
📖 Explanation: The entry section requests permission; the critical section accesses protected shared state; the exit section relinquishes permission; and the remainder section performs unrelated work. This order clearly separates coordination from ordinary computation.
Q2. [Entry section] A thread must request access before updating a shared inventory record. Which part of its execution contains the permission request and any waiting needed before the update?
📖 Explanation: The entry section contains the protocol used to request permission to access protected data. A process may wait there until admission is safe; the shared update itself belongs in the critical section.
Q3. [Exit section] A process has finished modifying a protected shared record. What is the main purpose of the code that follows the critical section immediately?
📖 Explanation: The exit section performs the actions that relinquish the process claim on the critical section. This lets an eligible contender proceed, while unrelated work should remain outside the protected region.
Q4. [Remainder section] A banking process finishes its protected balance update and then formats a private receipt using local variables only. Where does receipt formatting belong?
📖 Explanation: Receipt formatting uses only process-local data and does not require coordinated access to the shared balance. It therefore belongs in the remainder section, after the protected operation and its exit protocol.
Q5. [Mutual exclusion] Two processes access the same shared structure, and simultaneous updates could corrupt its links. Which condition must a correct critical-section protocol guarantee?
📖 Explanation: Mutual exclusion requires that at most one participating process execute the relevant critical section at any moment. It does not require equal delays or uninterrupted execution, and preemption may occur safely.
Q6. [Mutual exclusion application] Two warehouse workers read a stock value of 1, each decide that one item is available, and both decrement it. Which protection would prevent this conflicting sequence?
📖 Explanation: The availability check and decrement form one logical operation on shared state. Protecting the whole sequence prevents both workers from acting on the same old value and selling more items than remain.
Q7. [Graph: mutual exclusion] A plot gives time and the number of processes simultaneously inside one critical section: (0,0); (1,1); (2,2); (3,1); (4,0); (5,0). Which observation proves a violation?
📖 Explanation: At time 2, the plotted count is two, so two processes occupy the same protected region simultaneously. That directly violates mutual exclusion; the zero and one counts do not demonstrate overlapping execution.
Q8. [Error analysis] A student writes code that locks a shared record, changes its status, unlocks it, and only then writes the new owner identifier. What is the flaw?
📖 Explanation: The flawed step is unlocking before writing the owner identifier. The correct boundary keeps both related writes protected, so another process cannot observe or modify a partially updated record during the operation.
Q9. [Mixed: shared invariant] An online store transfers one unit from available stock to reserved stock. Which design best preserves the invariant that available plus reserved stock remains unchanged during each transfer?
📖 Explanation: The two fields represent one logical stock transfer and share an invariant. Keeping both updates inside the same critical section prevents another process from observing the temporary state between decrementing available stock and incrementing reserved stock.
Q10. [Error analysis] A shared record has fields balance and status. A writer updates both while protected, but a reader accesses them without using the same coordination protocol. What risk remains?
📖 Explanation: The writer-only protocol does not coordinate the reader with the update. The reader may observe one new field and one old field; readers must use compatible synchronization or a safe snapshot mechanism.
Q11. [Critical-section boundary] A consumer checks that a shared queue is nonempty and then removes its first item. Another consumer may act between these steps. What should be protected together?
📖 Explanation: The queue check and removal depend on the same shared state. Protecting them together prevents a second consumer from removing the final item after the first consumer checks, leaving the first with an invalid assumption.
Q12. [Critical-section scope] A process updates a shared counter and then compresses a private log buffer for several seconds. Which design is generally preferable?
📖 Explanation: Only the counter update requires coordinated access. Releasing protection before private compression shortens the critical section, reduces contention, and lets other processes use the shared counter without affecting the log operation.
Q13. [Progress] The critical section is empty and several processes request entry. Which requirement says that choosing the next entrant must not be postponed indefinitely?
📖 Explanation: Progress requires a decision among eligible requesters when no process occupies the critical section. That decision cannot be delayed forever, and processes doing unrelated remainder work must not prevent admission.
Q14. [Error analysis] A two-process protocol forces strict alternation. P1 leaves its critical section, making P0 next; P0 performs a long private calculation, while P1 requests entry again and must wait. What is wrong?
📖 Explanation: The flawed rule makes P1 depend on P0 even though P0 has no pending request. Progress requires that a process in its remainder section cannot unnecessarily prevent an eligible requester from entering.
Q15. [Progress] A critical section is free. Process A requests entry, but the protocol waits for process B to change a shared indicator; B is performing unrelated remainder work and has not requested entry. Which requirement is endangered?
📖 Explanation: B is not competing for the critical section, yet its unrelated activity determines whether A can proceed. This violates the progress principle that only interested contenders should influence the admission decision.
Q16. [Graph: progress] At every sample, the critical section is empty and two requests remain pending. The plot shows time and cumulative admissions: (0,0); (1,0); (2,0); (3,0); (4,0); (5,0). Assume this pattern continues indefinitely. What fails?
📖 Explanation: The section stays empty while eligible requests remain pending and no admission occurs indefinitely. The selection decision is postponed forever, which is a progress failure rather than evidence of overlapping access.
Q17. [Mixed: safety and liveness] A coordinator grants entry to only one process at a time, but then stops responding while the critical section is free and several processes are waiting. Which conclusion is most accurate?
📖 Explanation: Single-grant behavior can preserve the safety condition of mutual exclusion. If the coordinator never selects another requester, however, the empty critical section remains unused and progress is not guaranteed for waiting processes.
Q18. [Challenging: progress] Process P is waiting to enter an empty critical section. The algorithm will admit P only after process R changes a flag, but R has no request pending and may remain in its remainder section indefinitely. What is the key defect?
📖 Explanation: The admission decision depends on R even though R is not requesting access. Since R may remain in unrelated work, P can wait indefinitely while the section is free, violating progress.
Q19. [Bounded waiting] After a process requests entry, what does bounded waiting place a limit on?
📖 Explanation: Bounded waiting limits how many times other processes may enter after a request is made and before that request is granted. It prevents unlimited overtaking, rather than specifying a fixed elapsed-time deadline.
Q20. [Bounded-waiting application] A protocol claims a waiting process can be bypassed by at most two other entries. P requests access, but three other critical-section entries occur before P is admitted. What follows?
📖 Explanation: The claimed maximum is two other entries after P requests access. A third entry occurs before P is admitted, so the protocol exceeds its stated bound even though P eventually enters.
Q21. [Graph: bounded waiting] P has requested entry, and the plot shows the cumulative number of entries by other processes: (0,0); (1,1); (2,1); (3,2); (4,3); (5,4). If the permitted bound is 3, when is it first exceeded?
📖 Explanation: A bound of three allows at most three other entries before P is admitted. The plotted count first exceeds three at sample 5, where four other entries have occurred, so the bounded-waiting guarantee has failed.
Q22. [Error analysis] A student argues that bounded waiting is guaranteed because some process always enters whenever the critical section becomes free. Which correction is best?
📖 Explanation: The student confuses progress with bounded waiting. Progress ensures that some eligible process proceeds; bounded waiting adds an individual guarantee limiting how many other entries may occur before a particular waiting request is served.
Q23. [Bounded waiting] A protocol guarantees that no request is passed by more than four other entries. Which statement does this guarantee establish most directly?
📖 Explanation: The guarantee limits overtaking by other critical-section entries. It does not establish a wall-clock deadline, because processor scheduling and execution speeds can affect elapsed time even when the number of bypasses is bounded.
Q24. [Fair admission] Three requests receive positions 10, 11, and 12 in an ordered waiting line. If request 11 is waiting, what does strict service in line order guarantee about request 12?
📖 Explanation: Strict service order prevents a later request from overtaking an earlier pending request. Request 12 must wait until request 11 has been served, which supports bounded overtaking when the queue advances correctly.
Q25. [Execution assumptions] Two processes may run at very different speeds, and neither speed is known in advance. What must a correct critical-section solution avoid assuming?
📖 Explanation: A correct protocol cannot rely on one process being faster or slower than another. It must preserve its guarantees across possible execution interleavings without requiring equal processor speeds or predictable timing.
Q26. [Error analysis] A team tests a critical-section algorithm for billions of executions without observing overlap and declares it formally correct. What is the flaw in this reasoning?
📖 Explanation: The flawed step equates many successful tests with proof of correctness. Testing samples executions; a valid argument must establish the required properties for every permitted interleaving and the assumptions of the implementation.
Q27. [Graph: contention] A server is tested with the same workload and number of contenders. The plot gives average critical-section duration and average waiting time in milliseconds: (1,2); (2,4); (3,8); (4,15); (5,25); (6,39). Which trend is supported?
📖 Explanation: Across the measured workload, average waiting rises from 2 to 39 milliseconds as protected duration grows from 1 to 6 milliseconds. Longer occupancy leaves contenders waiting longer, although the graph alone cannot prove fairness.
Q28. [Mixed: interleavings] A programmer assumes that two processes cannot read the same old shared value because their instructions usually execute at different times. Which response is technically sound?
📖 Explanation: Processes can be interleaved at instruction boundaries in ways that make both read the same old value. A correct protocol must handle all permitted schedules instead of relying on typical timing or priority differences.
Q29. [Safety and liveness] Which classification best describes the three standard correctness requirements for the critical-section problem?
📖 Explanation: Mutual exclusion prevents an unsafe overlap, making it a safety condition. Progress and bounded waiting concern whether eligible requests can advance and avoid indefinite postponement, so they express liveness requirements.
Q30. [Mixed: evaluate a trace] In a trace, no two processes overlap in the critical section, and every requester eventually enters. However, one request can be passed by an arbitrarily large number of later entries. Which assessment is correct?
📖 Explanation: No overlap satisfies mutual exclusion, and eventual admission for some eligible requester is consistent with progress. An arbitrarily large number of bypasses means there is no finite waiting bound for the affected request.
Q31. [Scenario: critical-section boundary] An order-processing thread decreases available stock, increases reserved stock, and then sends a receipt over a slow network. Which work should remain inside the critical section?
📖 Explanation: The stock decrement and reservation increment jointly preserve the inventory invariant, so they must be coordinated as one operation. Network transmission does not modify that shared state and should occur after protection is released.
Q32. [Challenging: preserve an invariant] A buffer has capacity 20, with 8 occupied slots and 12 free slots. A producer inserts one item by decrementing free and incrementing occupied. Why should both counter updates be protected together?
📖 Explanation: The invariant is free plus occupied equals 20. If another process observes the state between the two writes, the reported total may temporarily be 19 or 21; protecting both writes preserves the logical invariant.
Q33. [Error analysis] A warehouse program checks that stock is positive before acquiring protection, then enters the critical section and decrements stock without checking again. Two workers may execute concurrently. What must be corrected?
📖 Explanation: The flawed step is checking availability before entering the protected region. Another worker can change stock before the decrement; the correct sequence performs both the check and decrement while access is coordinated.
Q34. [Scenario: shared record] A monitoring service updates a sensor value and its timestamp as a pair. A reporting thread must never display a new value with an old timestamp. What is the appropriate critical-section boundary?
📖 Explanation: The value and timestamp form one logical record, so updates must be coordinated together. The reader also needs compatible protection or a consistent snapshot to avoid combining fields from different update versions.
Q35. [Critical-section size] A process holds shared-state protection while waiting for a remote server response, although the response is unrelated to the protected data. What is the main consequence?
📖 Explanation: The remote wait does not require exclusive access to the shared state. Holding protection during that delay lengthens the critical section, increases contention, and can reduce concurrency without improving correctness.
Q36. [Integrated scenario] Three tasks share a data structure. Task A updates two linked fields that must remain consistent, task B reads those fields together, and task C changes only its private local variable. Which design is sound?
📖 Explanation: A paired update and paired read must follow compatible coordination so B cannot observe an inconsistent combination. Task C touches only private state, so placing it in the same critical section would add unnecessary contention.