Concurrency & Parallelism MCQs for the NSCT

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

Concurrency and parallelism cover how a program runs several tasks at once: creating threads, protecting shared data with locks and semaphores, avoiding deadlock, and estimating speed-up from extra cores. It is topic 14 of the 16 in the Programming (C++/Java/Python) area, which carries 10% of the NSCT according to HEC's Areas of Competencies. Candidates averaged 47.8% accuracy in this area in 2026, per the HEC NSCT report.

The topic is introductory here. Operating Systems covers scheduling and synchronisation in more depth, and both follow Silberschatz's terms, so learning them once pays off twice.

Threads

A thread is a single sequence of execution inside a process. Threads of the same process share its code, heap, global variables and open files. Each thread has its own stack, program counter and registers.

Process Thread
Memory Own address space Shares the process's address space
Creation cost Higher Lower
Communication Pipes, sockets, shared memory set up explicitly Directly through shared variables
A crash affects That process The whole process
import threading

def task():
    print("child")

t = threading.Thread(target=task)
t.start()   # begins a new thread
t.join()    # waits for it to finish
print("main")   # always printed after "child"

In Java, t.start() creates the thread, while calling t.run() directly just runs the method in the current thread.

Exam angle: without join(), the order of output from different threads is not guaranteed. Questions that ask for "the output" usually contain a join() or a lock that fixes the order.

Locks

A race condition happens when threads access shared data, at least one writes, and the result depends on timing. count += 1 is three steps (read, add, write), so two threads can read the same value and lose an update. The code that touches shared data is the critical section, and a lock (mutex) makes it mutually exclusive:

lock = threading.Lock()
def work():
    global count
    for _ in range(1000):
        with lock:          # only one thread at a time
            count += 1

Other tools you should recognise:

Tool What it does
Mutex / Lock One owner at a time
RLock (reentrant lock) The owner may acquire it again without blocking
Counting semaphore Lets up to N threads in; wait/P decrements, signal/V increments
Java synchronized Locks the object's monitor around a method or block
Java volatile Visibility of writes only; count++ is still not atomic
AtomicInteger Atomic read-modify-write operations

Deadlock needs all four Coffman conditions at once: mutual exclusion, hold and wait, no preemption and circular wait. The usual fix in code is a fixed lock order, which breaks circular wait. Compare deadlock with livelock, where threads stay active but make no progress, and starvation, where one thread waits indefinitely while others proceed.

Exam angle: "two threads lock A and B in opposite orders" is the standard deadlock question. The answer is to lock in the same order everywhere.

Parallel vs concurrent

Concurrency means several tasks are in progress over the same period. One core can do this by interleaving them. Parallelism means tasks execute at the same instant on several cores. A concurrent program may or may not run in parallel.

Three examples show the difference: - Two threads on a single core are concurrent but not parallel. - Python's asyncio is concurrency on one thread. While one coroutine waits on I/O, another runs. - In standard CPython, the Global Interpreter Lock (GIL) lets one thread run Python bytecode at a time. CPU-bound threads therefore do not run in parallel; use multiprocessing instead. Python 3.13 and later offer an optional free-threaded build.

Amdahl's law limits the speed-up from N processors when only a fraction p of the work can be parallelised:

Speed-up = 1 / ((1 − p) + p / N)

p (parallel) N = 2 N = 4 N → ∞
50% 1.33 1.6 2
70% 1.54 2.11 3.33
90% 1.82 3.08 10

Exam angle: the limit as N grows is 1 / (1 − p). If 10% of a program is serial, it can never run more than 10 times faster.

Common traps

Worked examples

1. Understanding. Why is creating a thread usually cheaper than creating a process? Answer: a new thread shares its process's address space, code and open files, so the OS only allocates a stack and a register context. A new process needs its own address space and resource tables.

2. Application. 95% of a program is parallelisable. What is the speed-up on 8 cores, and what is the maximum on any number of cores? Answer: 1 / (0.05 + 0.95/8) = 1 / 0.16875 ≈ 5.93. The maximum is 1 / 0.05 = 20.

3. Analysis. Thread A updates count inside with lock:, but Thread B updates count without taking the lock. Is the counter safe? Answer: no. A lock only excludes threads that also try to acquire it, so B can still interleave with A's read-add-write and updates can be lost. Every access to the shared variable must use the same lock.

Practise

The quiz below has 100 questions on concurrency and parallelism, filterable by tier and difficulty.

Practise: 100 questions

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

  1. Which statement correctly separates concurrency from parallelism?

    1. Parallelism is possible on a single core; concurrency needs more than one core
    2. They are two names for the same thing
    3. Concurrency applies only to processes and parallelism only to threads
    4. Concurrency is possible on a single core; parallelism needs more than one processing unit
    Show answer

    Answer: D. Concurrency is possible on a single core; parallelism needs more than one processing unit

    Concurrency means several tasks are in progress during the same period, which one core can achieve by interleaving them. Parallelism means tasks literally execute at the same instant, which needs several cores or processors. Parallel execution is one way of running a concurrent program.

  2. Which resource is private to each thread rather than shared by all threads of the same process?

    1. The heap
    2. Global variables
    3. Its stack (and register values)
    4. Open files
    Show answer

    Answer: C. Its stack (and register values)

    Threads of one process share its address space: code, heap, globals and open files. Each thread has its own stack, program counter and registers so it can run its own sequence of calls (Silberschatz).

  3. What is a race condition?

    1. A thread that runs faster than the others
    2. A bug where the result depends on the unpredictable timing or interleaving of threads
    3. A deadlock involving more than two threads
    4. A compiler optimisation that reorders loops
    Show answer

    Answer: B. A bug where the result depends on the unpredictable timing or interleaving of threads

    A race condition occurs when two or more threads access shared data, at least one writes, and the outcome depends on the order in which their operations happen to interleave. It is fixed by synchronisation, such as a lock around the shared update.

  4. What is a critical section?

    1. The first function that runs when a thread starts
    2. A piece of code that accesses shared data and must not be executed by two threads at once
    3. Code that handles fatal exceptions
    4. The part of a program with the highest CPU usage
    Show answer

    Answer: B. A piece of code that accesses shared data and must not be executed by two threads at once

    A critical section is code that reads or updates shared resources. Correct synchronisation guarantees mutual exclusion: while one thread is in its critical section, no other thread may be in its critical section for the same data.

  5. How does a counting semaphore initialised to 3 differ from a mutex?

    1. Up to three threads can hold it at once, while a mutex allows only one owner
    2. It allows exactly three threads in total over the whole program run
    3. It can be released only by the thread that acquired it, unlike a mutex
    4. It is used only for processes, while a mutex is only for threads
    Show answer

    Answer: A. Up to three threads can hold it at once, while a mutex allows only one owner

    A counting semaphore lets up to its value of threads proceed; further wait() calls block until someone calls signal(). A mutex is a lock with a single owner, and only that owner should unlock it. Semaphores have no owner, so any thread may signal.

  6. Which of these is NOT one of the four necessary conditions for deadlock (the Coffman conditions)?

    1. Mutual exclusion
    2. Hold and wait
    3. Circular wait
    4. Bounded waiting
    Show answer

    Answer: D. Bounded waiting

    The four conditions are mutual exclusion, hold and wait, no preemption and circular wait. Deadlock is possible only when all four hold together. Bounded waiting is a requirement for a correct critical-section solution, not a deadlock condition.

  7. Why do CPU-bound Python threads usually give little speed-up in standard CPython?

    1. Python threads are always run on a single core by the operating system
    2. Python does not support threads, only coroutines
    3. The Global Interpreter Lock lets only one thread run Python bytecode at a time
    4. Each thread copies the whole program, which wastes the time saved
    Show answer

    Answer: C. The Global Interpreter Lock lets only one thread run Python bytecode at a time

    In the default CPython build, the GIL allows one thread to execute bytecode at a time, so CPU-bound threads take turns rather than running in parallel. I/O-bound threads still benefit, because the GIL is released while waiting. For CPU-bound work use multiprocessing; Python 3.13 and later also offer an optional free-threaded build.

  8. In Java, what does marking an instance method synchronized do?

    1. The calling thread must acquire the object's intrinsic lock before running the method
    2. The method runs in a new thread each time it is called
    3. The method's local variables become shared between threads
    4. The method is guaranteed to run before any other method of the class
    Show answer

    Answer: A. The calling thread must acquire the object's intrinsic lock before running the method

    A synchronized instance method locks the object's monitor (this). Only one thread at a time can run any synchronized method on that same object; others block until the lock is released. Static synchronized methods lock the Class object instead.

  9. What does calling t.join() on a thread t do?

    1. The calling thread waits until t has finished
    2. It starts t
    3. It merges t into the main thread so they share a stack
    4. It stops t immediately
    Show answer

    Answer: A. The calling thread waits until t has finished

    join() blocks the caller until the target thread terminates (or a timeout passes, if one is given). It is the standard way to wait for worker threads before using their results. start() is what begins a thread.

  10. A Java programmer calls t.run() instead of t.start() on a Thread object. What happens?

    1. A new thread is created, exactly as with start()
    2. run() executes in the current thread, so no new thread is created
    3. A compile-time error occurs
    4. An IllegalThreadStateException is thrown
    Show answer

    Answer: B. run() executes in the current thread, so no new thread is created

    run() is an ordinary method call, so its body runs synchronously in the caller's thread. Only start() asks the JVM to create a new thread, which then calls run(). Calling start() twice on the same thread is what throws IllegalThreadStateException.

FAQs

What is the difference between a mutex and a binary semaphore?

Both allow one thread at a time. A mutex has an owner: the thread that locked it should be the one to unlock it, and reentrant variants let the owner lock it again. A binary semaphore has no owner, so any thread may signal it, which makes it suitable for signalling between threads as well as for mutual exclusion.

Is Python good for parallel programming?

For I/O-bound work, threads and asyncio work well, because waiting releases the GIL. For CPU-bound work in standard CPython, use multiprocessing or concurrent.futures.ProcessPoolExecutor. Each process has its own interpreter, so they can use several cores. Libraries such as NumPy also release the GIL inside their compiled code.

How can deadlock be prevented in code?

Break at least one of the four Coffman conditions. In practice, programmers usually do one of three things. They acquire locks in a fixed global order, which removes circular wait. They acquire all needed locks at once, or give up and retry with a timeout, which removes hold and wait. Or they avoid holding a lock while calling unknown code.

Next step

Continue to Debugging, Testing & Optimization MCQs, where race conditions return as hard-to-find bugs. Revisit the Programming MCQs hub or test yourself in an NSCT mock test.