Concurrency & Synchronization MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Concurrency and synchronisation is about keeping shared data correct when several processes or threads run at the same time. Without it you get race conditions, and the standard tools against them are mutex locks, semaphores and monitors. It is topic 6 of the Operating Systems area, which carries 5% of the NSCT according to HEC's Areas of Competencies. Operating Systems had the lowest accuracy of any area in 2026, at 33.8%, per the HEC NSCT report and APP, so careful tracing pays off here.

We follow Silberschatz's Operating System Concepts. Threads themselves are covered in Thread Management.

Race conditions

A race condition occurs when several threads access and change shared data concurrently and the result depends on the order of access. The cause is that a statement such as count++ is really three machine steps: load, add, store.

Example: count = 7. T1 runs count++ and T2 runs count--.

Step T1 T2 count
1 load 7, add 1 (register = 8) 7
2 load 7, subtract 1 (register = 6) 7
3 store 8 8
4 store 6 6

The correct answer is 7, but an interleaving can also give 6 or 8.

The fix is a critical section, the code that touches shared data, protected by an entry and exit protocol. A correct solution must provide mutual exclusion (one process inside at a time), progress (if no one is inside, the choice of who enters next cannot be postponed forever) and bounded waiting (a limit on how many times others can overtake a waiting process).

Exam angle: to find the possible final values, list the interleavings of loads and stores; a "lost update" happens when a stale register value is stored last.

Hardware and software foundations

Peterson's solution solves the problem for two processes with flag[2] and turn, but modern CPUs may reorder memory operations, so it is not guaranteed to work on them without memory barriers. Hardware offers atomic instructions such as test_and_set() (return the old value and set to true) and compare_and_swap() (set to the new value only if the current value equals the expected one; always return the old value).

Mutex

A mutex lock has two operations, acquire() and release(), and a boolean "available". A thread must acquire it before the critical section and release it afterwards. If the lock spins while waiting it is a spinlock: it wastes CPU but avoids context switches, so it suits multicore systems with very short critical sections.

acquire(lock);
    balance = balance + deposit;    /* critical section */
release(lock);

Exam angle: a mutex usually has an owner, so only the thread that acquired it should release it. A semaphore has no owner.

Semaphores

A semaphore S is an integer accessed only through two atomic operations: wait() (P), which decrements it, and signal() (V), which increments it. A binary semaphore ranges over 0 and 1 and behaves much like a mutex; a counting semaphore is initialised to the number of available resources.

Where books differ: the classical busy-waiting definition never lets S drop below 0. Silberschatz's blocking implementation lets S go negative; its magnitude is then the number of waiting processes.

Semaphores also enforce order. To make S2 in P2 run after S1 in P1, set synch = 0; P1 runs S1; signal(synch); and P2 runs wait(synch); S2;.

Exam angle: misuse is a favourite question. signal before the critical section breaks mutual exclusion, and two processes taking two semaphores in opposite order can deadlock.

Tool Value Owner Typical use
Mutex Locked or unlocked Yes Mutual exclusion
Binary semaphore 0 or 1 No Mutual exclusion or signalling
Counting semaphore Any integer No Pools of N identical resources
Monitor Built-in lock plus condition variables Implicit Structured mutual exclusion

Monitors

A monitor is a high-level construct that packages shared data with the procedures that use it, and guarantees that only one process is active inside at a time. Condition variables let a process wait inside the monitor: x.wait() suspends it, and x.signal() resumes one waiting process. If no process is waiting, x.signal() has no effect, unlike a semaphore's signal().

When P signals Q, one of them must wait. Under signal-and-wait, P waits and Q runs. Under signal-and-continue, P continues and Q runs later, so Q must recheck its condition in a while loop.

Exam angle: the producer-consumer, readers-writers and dining-philosophers problems use these tools; they are covered in depth in Semaphores and Classic Sync Problems.

Common traps

Worked examples

1. Understanding. What is busy waiting, and how does a semaphore avoid it? Answer: busy waiting means a waiting process loops, testing the lock and wasting CPU cycles. A blocking semaphore puts the process on the semaphore's waiting queue and suspends it; signal() later moves it back to the ready queue.

2. Application. S = 2. Processes run, in order: A wait, B wait, C wait, A signal, D wait. What is S after each step, and who is blocked at the end? Answer: S goes 1, 0, -1 (C blocks), 0 (A's signal wakes C), -1 (D blocks). At the end S = -1 and only D is blocked; B and C hold the resource.

3. Analysis. x = 0. T1 runs x = x + 2 and T2 runs x = x * 3, each as load, compute, store. What final values are possible? Answer: 0, 2 or 6. Serial orders give (0 + 2) x 3 = 6 or 0 x 3 + 2 = 2. If both load 0 and T1 stores last, x = 2; if T2 stores last, x = 0. An exhaustive interleaving search confirms exactly {0, 2, 6}.

Practise

The quiz below has 100 Concurrency & Synchronization questions, filterable by tier and difficulty.

Practise: 100 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. When several threads access and change shared data concurrently and the result depends on the order in which the accesses happen, the situation is called:

    1. A deadlock
    2. Starvation
    3. Thrashing
    4. A race condition
    Show answer

    Answer: D. A race condition

    That is Silberschatz's definition of a race condition. It arises when an operation such as count++ is really several machine instructions (load, add, store) that can be interleaved. Synchronisation ensures only one thread manipulates the shared data at a time.

  2. The segment of code in which a process accesses and updates data shared with other processes is called its:

    1. Remainder section
    2. Critical section
    3. Entry section
    4. Exit section
    Show answer

    Answer: B. Critical section

    The critical section is where shared data is touched. A process asks permission in the entry section, releases it in the exit section, and runs unrelated code in the remainder section.

  3. Which of these is NOT one of the three requirements a solution to the critical-section problem must satisfy?

    1. The critical section must finish within one time quantum
    2. Mutual exclusion
    3. Progress
    4. Bounded waiting
    Show answer

    Answer: A. The critical section must finish within one time quantum

    A correct solution needs mutual exclusion (one process inside at a time), progress (if none is inside, the choice of who enters next cannot be postponed indefinitely) and bounded waiting (a limit on how many times others can enter ahead of a waiting process). No time-quantum rule exists.

  4. The bounded-waiting requirement of the critical-section problem guarantees that:

    1. A process spends at most a fixed time inside its critical section
    2. The waiting queue of a semaphore has a fixed maximum length
    3. No process ever needs to wait to enter
    4. After a process asks to enter, others can enter only a limited number of times before it does
    Show answer

    Answer: D. After a process asks to enter, others can enter only a limited number of times before it does

    Bounded waiting limits how many times other processes may enter their critical sections after a process has requested entry and before that request is granted. It prevents starvation; it says nothing about how long a process stays inside.

  5. For a semaphore to work correctly, its wait() and signal() operations must be:

    1. Executed only by the operating system's scheduler
    2. Called the same number of times by every process
    3. Executed atomically
    4. Called only on single-core processors
    Show answer

    Answer: C. Executed atomically

    wait() tests and decrements the value and signal() increments it. If two processes could run these at the same time, updates to the value could be lost, which is itself a race. So each operation must be indivisible (atomic).

  6. A counting semaphore controls access to 5 identical printers. What should it be initialised to?

    1. 1
    2. 0
    3. 4
    4. 5
    Show answer

    Answer: D. 5

    A counting semaphore is initialised to the number of available instances. Each wait() takes one printer and each signal() returns one. When the value reaches 0, all printers are in use and further wait() calls block.

  7. Peterson's solution to the critical-section problem uses which shared variables for two processes?

    1. A single semaphore initialised to 1
    2. A boolean array flag[2] and an int turn
    3. A test_and_set lock variable
    4. A monitor with one condition variable
    Show answer

    Answer: B. A boolean array flag[2] and an int turn

    Peterson's software solution uses flag[i] to say process i is ready to enter, and turn to say whose turn it is. A process enters only if the other is not ready or it is its own turn. It needs no special hardware instructions.

  8. What does a monitor guarantee about the processes using it?

    1. Every process inside runs at the same priority
    2. Processes inside can never block
    3. Only one process at a time can be active inside the monitor
    4. Each process gets its own copy of the monitor's data
    Show answer

    Answer: C. Only one process at a time can be active inside the monitor

    A monitor is an abstract data type whose procedures run with mutual exclusion built in: only one process can be active in it at any time. Condition variables (x.wait(), x.signal()) let processes inside wait for specific conditions.

  9. When is a spinlock (busy-waiting mutex) a better choice than a lock that puts the waiting thread to sleep?

    1. On a single-core system when the lock is held for a long time
    2. Whenever the critical section performs disk I/O
    3. When there are many more threads than cores
    4. On a multicore system when the lock is held only for a very short time
    Show answer

    Answer: D. On a multicore system when the lock is held only for a very short time

    Spinning wastes CPU, but it avoids two context switches. On multicore systems with short critical sections, the lock is often released before a sleep-and-wake would have finished, so spinning is faster. On a single core the holder cannot run while another thread spins.

  10. Which property usually distinguishes a mutex lock from a binary semaphore?

    1. A mutex can take any non-negative integer value
    2. A binary semaphore can never cause blocking
    3. A mutex can be used only between processes, never threads
    4. A mutex has an owner: only the thread that acquired it should release it
    Show answer

    Answer: D. A mutex has an owner: only the thread that acquired it should release it

    A mutex is acquired and released by the same thread, and many implementations enforce that ownership. A binary semaphore has no owner, so one thread can wait() and another signal(), which suits signalling. Silberschatz notes the two behave similarly for plain mutual exclusion; the ownership rule is where implementations differ.

FAQs

What is the difference between a mutex and a semaphore?

A mutex is a lock with an owner: the thread that acquires it releases it, and it is used for mutual exclusion. A semaphore is an integer counter with wait() and signal() and no owner, so one thread can signal another. A counting semaphore can also manage several identical resources.

What are the three requirements of the critical-section problem?

Mutual exclusion: only one process runs in its critical section at a time. Progress: if no process is inside, the processes that want to enter decide who goes next without indefinite delay. Bounded waiting: once a process asks to enter, others can enter only a limited number of times before it does.

Can a semaphore have a negative value?

It depends on the definition. In the classical busy-waiting version, wait() loops until S is positive, so S never goes below 0. In Silberschatz's blocking implementation, wait() decrements first, so S can be negative; then its magnitude equals the number of processes waiting on it.

What is priority inversion?

A high-priority task waits for a lock held by a low-priority task, while a medium-priority task preempts the low-priority one, so the high-priority task is effectively delayed by a lower one. Priority inheritance fixes it by temporarily giving the lock holder the waiter's priority.

Next step

Continue to Deadlocks, drill semaphores and classic problems, return to the Operating Systems MCQ hub, or take a timed NSCT mock test.