🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Process Synchronization in operating system (36 MCQs)

Coordinating Concurrent Processes and Shared Resources

Process synchronization is a process-management mechanism that coordinates concurrent processes or threads accessing shared data and resources. It ensures that operations execute in an appropriate order and that conflicting updates do not corrupt shared information. Synchronization mechanisms include critical sections, mutex locks, semaphores, monitors, and hardware atomic instructions. The operating system and application programs use these mechanisms to preserve data consistency during concurrent execution.

Why Concurrent Execution Creates Race Conditions

Multiple processes may read and modify the same variable, file, or shared-memory region. When their instructions interleave unpredictably, the final result can depend on execution timing. This race condition makes program behaviour unreliable. Synchronization establishes controlled access and ordering, preventing conflicting operations while preserving concurrency wherever simultaneous execution is safe.

Mutual Exclusion, Progress, and Bounded Waiting

A process enters a critical section after acquiring an appropriate synchronization mechanism. Other competing processes must wait until the protected operation finishes. A correct critical-section solution aims to provide mutual exclusion, progress, and bounded waiting. The implementation may use atomic hardware instructions, blocking primitives, or higher-level constructs such as monitors.

Race Condition During a Shared Counter Update

Suppose two threads increment a shared counter initially containing 10. Both read 10 before either writes the updated value. Each calculates 11 and stores it, leaving the counter at 11 instead of the expected 12. Protecting the increment operation with a mutex ensures that both updates occur without conflicting interleaving.

Data Consistency, Concurrency, and Synchronization Overhead

Synchronization protects shared information in databases, operating system kernels, file systems, and multithreaded applications. It prevents race conditions and supports reliable resource allocation. However, excessive locking increases waiting time and reduces parallelism. Incorrect lock ordering can cause deadlocks, while unfair access policies can produce starvation among competing execution activities.

Misconceptions About Concurrent Process Execution

'Synchronization always means executing processes sequentially' is incorrect because independent operations can remain concurrent. 'Atomic variables eliminate every race condition' is incorrect because compound operations may still conflict. 'Mutual exclusion guarantees bounded waiting' is incorrect because a lock may prevent simultaneous entry while still allowing indefinite postponement.

Exam Focus: Race Conditions and Critical-Section Requirements

Trace concurrent instruction sequences and identify race conditions involving shared variables. Explain mutual exclusion, progress, and bounded waiting, distinguishing their individual requirements. Compare mutexes, semaphores, monitors, and hardware atomic operations. Questions may present interleaved execution sequences and ask you to determine the final shared value or identify an appropriate synchronization mechanism.

Key Terms of Process Synchronization

  • Race condition - Result dependent on execution timing.
  • Critical section - Code accessing protected shared data.
  • Mutual exclusion - Prevents simultaneous protected access.
  • Progress - Ensures eligible entry decisions proceed.
  • Bounded waiting - Limits postponement before entry.
  • Atomicity - Guarantees indivisible operation execution.
12
Easy
12
Medium
12
Hard

📝 All Process Synchronization in operating system MCQs

Q1. Two worker threads each execute 100 separate read, increment, and write operations on a shared counter initially equal to 0. No synchronization is used. Which result is possible?

A.The final value must be 200 because every increment is executed
B.The final value may be below 200 because concurrent writes can overwrite updates ✅
C.The final value must be 100 because only one thread can access memory at a time
D.The final value is 200 whenever both threads have equal priority
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Each increment is a read-modify-write sequence, not necessarily one indivisible operation. If threads read the same old value, one update can overwrite the other. Lost updates can therefore leave the final counter below 200.

Q2. Which statement best describes the purpose of process synchronization when several processes share data?

A.It forces every process to execute to completion before another can start
B.It prevents the operating system from preempting any process
C.It guarantees that all processes receive identical CPU time
D.It coordinates conflicting accesses while allowing independent work to remain concurrent ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Synchronization controls the ordering of operations that share or depend on common state. It does not require unrelated work to run sequentially, and it does not replace CPU scheduling or guarantee equal processor time.

Q3. A trace records P1 inside a critical section from time 1 to 5 and P2 inside it from time 4 to 7. Which conclusion follows from this timeline?

A.Mutual exclusion is violated because the intervals overlap from time 4 to 5 ✅
B.Mutual exclusion holds because P1 entered before P2
C.Bounded waiting is proved because both processes eventually exit
D.Progress is violated because P2 entered after time 4
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: P1 occupies the critical section during the interval 1 to 5, while P2 occupies it during 4 to 7. Their simultaneous occupancy from time 4 to 5 violates mutual exclusion.

Q4. A banking service updates an account balance and a transaction counter as one logical operation. Which code region should be treated as the critical section?

A.The code that prints a completion message after the update
B.The code that calculates an unrelated display colour
C.The paired balance and transaction-counter updates that maintain the shared account state ✅
D.Every instruction executed by the banking service, including unrelated calculations
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A critical section contains the operations that access shared state requiring coordinated protection. Because the two updates maintain one account invariant, both belong inside the protected region; unrelated calculations need not be included.

Q5. Process P is executing a protected critical section. What does mutual exclusion require of a competing process Q?

A.Q may enter if it has a higher priority
B.Q must not enter its conflicting critical section until P leaves ✅
C.Q must terminate whenever P acquires the lock
D.Q may enter if both processes access the same variable only once
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Mutual exclusion permits at most one process at a time to execute the protected critical section for the same shared resource. Priority, instruction count, or the number of accesses does not remove that restriction.

Q6. A team uses a monitor to coordinate access to a shared buffer. Which feature is typically provided by a monitor construct?

A.It lets every thread execute monitor procedures simultaneously
B.It provides automatic mutual exclusion for monitor procedures and condition variables for waiting ✅
C.It guarantees FIFO scheduling for every process in the operating system
D.It removes the need to check shared-state conditions
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A monitor groups shared data and operations behind a construct that permits one process or thread at a time to execute its procedures. Condition variables support waiting for and signaling required states.

Q7. A critical section is empty, and processes P and Q both request entry. Which requirement says that an uninterested process outside the critical section must not delay the selection indefinitely?

A.Mutual exclusion
B.Atomicity
C.Bounded waiting
D.Progress ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Progress requires an entry decision to proceed when the critical section is free and contenders exist. Processes that are not requesting entry must not indefinitely control or postpone the selection of the next entrant.

Q8. A protocol promises that no more than two other successful entries may occur after a process requests access and before it enters. Which observation violates this guarantee?

A.Three other processes enter successfully before the requesting process is admitted ✅
B.The requester waits while the current owner finishes its critical section
C.The requester enters immediately when the lock is free
D.Only one other process enters before the requester
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Bounded waiting places a limit on how many competing entries may pass a requester. Three intervening entries exceed the stated maximum of two, whereas waiting for the current owner alone does not violate it.

Q9. Which situation is a race condition rather than merely concurrent execution?

A.Two processes calculate separate values without sharing data
B.A process is interrupted while executing instructions on private data
C.The final shared result depends on the unpredictable order of conflicting reads and writes ✅
D.Two independent processes are scheduled on separate processor cores
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Concurrent execution alone is not an error. A race condition occurs when operations access shared state without sufficient coordination and the observed result depends on their relative timing or interleaving.

Q10. A thread acquires a mutex before updating a shared queue and releases it after the update. What is the mutex intended to ensure?

A.The thread cannot be preempted anywhere in the program
B.Only one thread at a time performs the protected queue operation ✅
C.Every waiting thread receives the lock in arrival order
D.The queue never becomes empty
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A mutex provides exclusive ownership of a protected region while it is held. It does not by itself prevent preemption outside that region, promise FIFO fairness, or impose a particular queue length.

Q11. A counting semaphore represents four identical available devices and is initially 4. Four workers each acquire one permit successfully. What is its value afterward?

A.4
B.1
C.0 ✅
D.-4
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Each successful wait consumes one available permit. The count changes from 4 to 3, then 2, then 1, and finally 0. A fifth worker must wait until a permit is released.

Q12. Why is an atomic hardware instruction useful when implementing a lock?

A.It makes every instruction in the process execute without interruption
B.It guarantees FIFO ordering among all waiting processes
C.It removes the need to protect shared data
D.It combines a lock-state test and update into an indivisible operation ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Lock acquisition must not allow two contenders to observe an available state and both claim ownership. An atomic instruction makes the relevant test and state change indivisible, supporting mutual exclusion.

Q13. A student implements a lock by reading a shared Boolean flag and then setting it to true in a separate instruction. What is the flaw in this reasoning?

A.A Boolean variable cannot represent an available or occupied lock
B.Both processes may read false before either stores true, so both may enter ✅
C.A shared flag automatically blocks the second reader
D.The scheduler always serializes reads followed by writes to shared variables
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The flawed step is treating the separate read and write as one atomic acquisition. Both contenders can read false before either writes true. The corrected design uses an atomic operation or a proven locking protocol.

Q14. Two threads read counter value 10 and both attempt an atomic compare-and-swap from 10 to 11. What happens when both operations execute correctly?

A.Both succeed and the counter becomes 12
B.Both fail and the counter remains 10
C.One succeeds; the other fails because the expected value is no longer 10 ✅
D.The hardware delays both operations until one thread terminates
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The first successful compare-and-swap changes 10 to 11 atomically. The second operation then finds that the current value is not its expected value of 10, so it fails and must retry using the updated value.

Q15. Several processes repeatedly use an atomic test-and-set instruction to acquire one lock. What does atomicity guarantee by itself?

A.Only one contender can successfully acquire the lock at a time, but fairness is not assured ✅
B.Every contender acquires the lock in arrival order
C.Every contender eventually acquires the lock after a fixed number of attempts
D.The lock holder cannot be interrupted by the scheduler
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Atomic test-and-set serializes competing lock-state updates and can enforce mutual exclusion. It does not record arrival order or bound the number of failed attempts, so a process may repeatedly lose and starve.

Q16. In a strict-alternation protocol, P may enter only when turn equals P. P wants to enter, but turn belongs to Q, which remains in its remainder section. Which property can fail?

A.Mutual exclusion, because both processes necessarily enter together
B.Atomicity, because the turn variable has two values
C.Deadlock freedom, because Q is executing its critical section
D.Progress, because an uninterested Q can prevent P from entering an empty section ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Strict alternation can prevent simultaneous entry, yet still block a process when the other process does not want the critical section. Progress is violated because an uninterested process controls admission despite the section being free.

Q17. A producer writes a payload and then sets a ready flag; a consumer observes the flag and reads the payload. What must the synchronization protocol guarantee?

A.The producer must always run on a faster processor
B.The payload write becomes visible to the consumer before the consumer reads after observing readiness ✅
C.The ready flag must be a floating-point value
D.The consumer must read the payload before checking readiness
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The flag alone is insufficient unless the memory model orders publication correctly. A release operation by the producer and a matching acquire operation by the consumer can ensure earlier payload writes become visible before the read.

Q18. A developer claims that declaring a shared variable volatile makes an unsynchronized increment safe. Which correction is accurate?

A.Volatile always turns an increment into one indivisible instruction
B.Volatile prevents every other process from reading the variable
C.Visibility or compiler-ordering effects do not generally make a read-modify-write sequence atomic ✅
D.Volatile guarantees that the highest-priority process performs each update
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The incorrect assumption is that visibility implies atomicity. A volatile declaration does not generally combine reading, adding, and writing into one indivisible operation. Use an atomic operation or protect the complete update with synchronization.

Q19. Thread A acquires lock L1 and then requests L2. Thread B acquires L2 and then requests L1. Which policy most directly prevents this particular circular wait?

A.Allow each thread to increase its priority while waiting
B.Release both locks whenever either thread is preempted
C.Use separate local copies of each lock variable
D.Require all threads to acquire locks in one consistent global order ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The conflicting acquisition orders let each thread hold one lock while waiting for the other. A consistent global order prevents this cycle by ensuring every thread requests the same lock sequence.

Q20. A payment operation changes both an account balance and its transaction count. A programmer locks only the balance update. What can still go wrong?

A.Another thread can observe or create an inconsistent relationship between the two shared values ✅
B.The lock automatically protects every variable used by the program
C.The transaction count becomes read-only while the balance lock is held
D.The operating system combines both updates into one atomic instruction
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A lock protects only operations included in its protocol. Because balance and transaction_count describe one logical state change, protecting one while leaving the other exposed can violate the invariant linking them.

Q21. A semaphore is initialized to 0. Process P executes wait, and process Q later executes signal. Under blocking semaphore semantics, what occurs?

A.P consumes one permit immediately and continues
B.P terminates because a zero initial value is invalid
C.P blocks until Q signals, after which P can become ready to continue ✅
D.Q blocks until P performs a signal
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A wait on a zero-count semaphore cannot consume a permit, so P blocks. Q then signals the semaphore, making a permit available or waking a waiting process according to the semaphore implementation.

Q22. A buffer has four slots and is initially empty. Which initial semaphore values correctly represent available slots and stored items?

A.empty = 0 and full = 4
B.empty = 4 and full = 0 ✅
C.empty = 4 and full = 4
D.empty = 1 and full = 1
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: An empty four-slot buffer has four available positions and contains no items. Therefore, empty starts at 4 and full starts at 0, preventing insertion beyond capacity and removal before an item exists.

Q23. A consumer waits on a condition variable until a shared queue contains an item. Why should it normally recheck the queue condition in a loop after waking?

A.A wake-up may be spurious, or another consumer may take the item first ✅
B.A condition variable permanently stores one item for each signal
C.The loop guarantees that the consumer runs before every producer
D.The queue cannot change while a thread is waiting
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A notification does not reserve an item or prove the predicate remains true. Spurious wake-ups and competing consumers are possible, so the thread must reacquire the mutex and test the queue condition again.

Q24. A service measures completed operations per second as worker count rises: (1,10), (2,19), (4,30), (8,32), and (16,21). Which interpretation best fits these results?

A.Throughput increases linearly because each added worker contributes equal capacity
B.The service is deadlocked at every worker count above 4
C.Synchronization has no measurable effect because throughput is never zero
D.Throughput peaks near 8 workers, then contention or another shared bottleneck outweighs added parallelism ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Throughput rises from 10 to 32 operations per second as workers increase to 8, then falls to 21 at 16. The decline suggests contention, resource saturation, or scheduling overhead rather than guaranteed linear scaling.

Q25. A queue producer holds the mutex, signals the consumer, and only afterward inserts the item. The consumer wakes, finds the queue empty, and waits again. What is the best correction?

A.Remove the consumer condition check so every signal causes a dequeue
B.Signal repeatedly until the consumer removes an item
C.Update the queue under its mutex before notifying the consumer ✅
D.Assume the notification stores the item for the consumer
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The flawed order announces a condition change before the shared predicate becomes true. Insert the item while holding the associated mutex, then notify; the consumer must still recheck the queue predicate after waking.

Q26. On a single-core machine, a lock holder is descheduled while another process continuously spins on the same lock. Why can this be especially inefficient?

A.The spinning process may consume CPU time that the lock holder needs to run and release the lock ✅
B.The spinlock automatically transfers ownership to the waiting process
C.A single core executes both processes simultaneously during the spin loop
D.The scheduler is required to run the spinner until it acquires the lock
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The waiter repeatedly consumes the only processor while the owner is not running. This can delay the owner from releasing the lock, so a blocking wait may be preferable when the owner is descheduled.

Q27. A driver holds a spinlock while waiting several milliseconds for disk I/O to finish. What is the strongest design objection?

A.Spinlocks cannot protect shared data
B.The disk controller releases every spinlock automatically
C.A long I/O wait wastes CPU cycles in competing spin loops ✅
D.A spinlock guarantees that waiting threads enter in FIFO order
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Spinning is suitable mainly when the owner is expected to release a lock quickly. Holding it across slow I/O can waste substantial processor time and may be invalid where sleeping is required.

Q28. A system completes work continuously, but one process repeatedly loses a lock race while others acquire and release the lock. Which conclusion is correct?

A.The system must be deadlocked because one process is waiting
B.Mutual exclusion has failed because several processes make progress
C.Progress automatically proves bounded waiting for every process
D.The system may be deadlock-free overall while the unlucky process suffers starvation ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Deadlock prevents a set of processes from progressing, whereas starvation can affect one process while others continue. Repeatedly bypassing the same waiter shows why system-wide progress does not guarantee individual fairness.

Q29. A running thread repeatedly releases and reacquires an unfair mutex before a waiting thread is scheduled. What risk does this pattern create?

A.The mutex necessarily allows two owners at once
B.The waiting thread may be postponed indefinitely despite repeated lock releases ✅
C.The scheduler permanently disables the waiting thread
D.The mutex becomes a counting semaphore with unlimited permits
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: An unfair acquisition policy may let the running thread win each reacquisition race. The waiter can therefore remain excluded despite the lock becoming free repeatedly, violating bounded-waiting expectations for that particular request.

Q30. A shared counter must be incremented, and an event must be triggered exactly once when the new value first reaches 100. Which approach preserves the requirement?

A.Increment atomically, then let every thread test the threshold using an unrelated unsynchronized read
B.Have each thread trigger the event when its private counter reaches 100
C.Protect the increment and threshold decision as one atomic state transition ✅
D.Sleep briefly after each increment and assume no other thread runs
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The increment and threshold decision form one logical operation. Protecting only the increment leaves a race in which multiple threads may trigger the event. One atomic transition or a lock covering both steps enforces exactly-once behavior.

Q31. A lock-free counter uses compare-and-swap loops. It performs well with two threads but slows sharply with 32 threads updating the same memory location. What is the most likely explanation?

A.Competing updates cause failed compare-and-swap attempts and repeated retries ✅
B.Lock-free algorithms cannot use atomic hardware instructions
C.The counter becomes nonnumeric when more than eight threads access it
D.The processor serializes all threads permanently after the first update
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Each successful compare-and-swap changes the value expected by competing threads, causing their attempts to fail. Under heavy contention, repeated retries and cache-coherence traffic can outweigh the benefit of avoiding blocking.

Q32. A timeline shows P1 holding a lock on [0,3), P2 waiting from 1 to 3, and P2 holding the lock on [3,6). Which property is demonstrated by this particular trace?

A.Mutual exclusion is violated because P2 requested entry before P1 exited
B.Bounded waiting is guaranteed for every possible execution
C.The trace proves that P1 and P2 never share data
D.Mutual exclusion is preserved in the displayed execution because the intervals do not overlap ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: P1 leaves at time 3, exactly when P2 begins, so the displayed critical-section intervals do not overlap. This trace is consistent with mutual exclusion, although one trace cannot prove universal correctness.

Q33. A programmer protects a linked-list traversal with a mutex, but another thread removes and frees a node without acquiring that mutex. What is the most serious risk?

A.The list automatically restores the removed node before the next read
B.The reader may dereference freed memory while traversing the list ✅
C.The mutex prevents memory reclamation even when the remover ignores it
D.The reader automatically becomes the owner of every removed node
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The lock protects the list only when every relevant access follows the same protocol. Removal without the lock can free a node that a reader still references, causing use-after-free errors, crashes, or corrupted data.

Q34. A developer protects every operation with one global mutex. Independent counters then update one at a time, reducing throughput as worker count grows. Which redesign is most appropriate?

A.Remove all locks even though the counters are shared
B.Increase the global critical section so every thread waits longer
C.Use separate locks for independent counters while preserving protection for each counter ✅
D.Force all workers to use the same priority
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: One global mutex serializes operations that do not conflict. Separate locks allow independent counters to be updated concurrently while preserving their individual invariants; operations acquiring multiple locks still need a consistent ordering policy.

Q35. A benchmark records CPU time spent spinning for critical-section durations: (1 microsecond, 2%), (5, 8%), (20, 31%), (50, 68%), and (100, 91%). What trend does the data show?

A.Spinning consumes a larger share of CPU time as the protected duration increases ✅
B.Spinning becomes free whenever the critical section exceeds 20 microseconds
C.The values prove that mutual exclusion fails at 100 microseconds
D.CPU time spent spinning decreases as the critical section becomes longer
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The measured spinning share rises from 2 percent at one microsecond to 91 percent at 100 microseconds. Longer lock hold times make busy-waiting increasingly costly, supporting blocking or a shorter critical section.

Q36. A database validates that an account has at least 400 units, then two concurrent requests each withdraw 400 from a balance of 500. Both validation steps occur before either update. What correction prevents an invalid combined withdrawal?

A.Increase the priority of both database workers
B.Delay each worker for a fixed interval after validation
C.Protect the validation and balance update as one isolated transaction or atomic conditional operation ✅
D.Allow both updates and correct the balance during the next restart
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Both requests can read 500 and independently pass validation, even though their combined withdrawals exceed the balance. Isolation or an atomic conditional update makes the second request observe the first committed withdrawal before proceeding.

🔗 Related Topics (MCQs)