🎓 BookMCQ
← Back to 4. Threads in Operating System

📝 Multicore programming challenges and issues (33 MCQs)

Coordination Problems in Multicore Software

Multicore programming introduces challenges when multiple threads execute simultaneously on separate processor cores. Important issues include dividing work, balancing workloads, partitioning data, managing shared resources, handling data dependencies, and synchronising execution. Although multicore hardware provides parallel execution capacity, software must be designed to use it safely and efficiently without producing inconsistent results or excessive coordination overhead.

Why Parallel Execution Is Difficult to Scale

Tasks often contain dependencies that prevent unrestricted simultaneous execution. Shared variables may be modified by several threads, producing race conditions if operations are not coordinated. Unequal task durations can leave some cores idle, while excessive locks may force threads to wait. These problems become more visible as the number of execution cores increases.

Task Partitioning, Data Partitioning, and Synchronisation

Developers divide workloads into independent tasks or data regions and assign them to worker threads. Locks, semaphores, atomic operations, and barriers coordinate shared activities. The scheduler distributes runnable threads across processor cores, while cache-coherence mechanisms support consistent shared-memory behaviour. Work-stealing and dynamic scheduling can help redistribute tasks when execution times are unpredictable.

Unequal Workloads Across Four Processing Cores

Suppose four threads process separate data partitions requiring 2, 3, 4, and 10 milliseconds. The first three cores finish early and remain underused while the fourth continues working. A suitable partitioning strategy or dynamic scheduling mechanism can redistribute independent work, reducing idle time and improving overall completion time.

Synchronisation Overhead, Cache Effects, and Scalability

Parallel applications can lose performance through lock contention, false sharing, cache misses, and communication between cores. Frequent synchronisation may reduce the amount of useful parallel work, while poor partitioning causes load imbalance. Increasing processor count can therefore produce diminishing returns. Correctness also requires memory-ordering guarantees and careful handling of shared data dependencies.

Misconceptions About Multicore Programming Difficulties

'Adding locks always makes parallel code faster' is incorrect because excessive locking creates contention. 'Equal numbers of tasks guarantee equal workloads' is incorrect because task execution times may differ. 'Cache coherence eliminates all shared-memory problems' is incorrect because it does not prevent race conditions, false sharing, or incorrect synchronisation.

Exam Focus: Load Balancing, Dependencies, and Race Conditions

Identify data and task dependencies that restrict parallel execution, and explain how locks and barriers coordinate threads. Analyse workload imbalance using processor execution times. Questions may test race conditions, false sharing, cache coherence, contention, and scalability, or ask why a program becomes slower when additional cores and threads are introduced.

Key Terms of Multicore Programming Challenges

  • Race condition - Result dependent on execution timing.
  • Load imbalance - Unequal work among processors.
  • False sharing - Unnecessary cache-line contention.
  • Lock contention - Competition to acquire a lock.
  • Barrier - Point requiring threads to wait.
  • Dependency - Relationship restricting execution order.
11
Easy
11
Medium
11
Hard

📝 All Multicore programming challenges and issues MCQs

Q1. A photo-processing program must apply the same filter independently to 400 image tiles. Which design step best exposes useful multicore work?

A.Assign independent groups of tiles to separate tasks that can run without waiting for one another ✅
B.Make every task update the same output pixel before any task finishes
C.Place all tiles in one sequential loop and assume the scheduler will split it automatically
D.Create a separate process for every pixel regardless of the work involved
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Task identification finds portions of an application that can proceed independently. Assigning separate tile groups exposes parallel work, while shared updates or an unchanged sequential loop do not automatically create independent execution paths.

Q2. A weather application calculates regional forecasts, then combines them into a national forecast. Which observation is most important when identifying tasks for concurrent execution?

A.Every calculation must use the national result before it can begin
B.Regional calculations may run independently, but the combining stage depends on their results ✅
C.The combining stage should always run before regional calculations
D.All stages are independent because they belong to one application
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Regional forecasts can be computed concurrently when they use independent inputs. The national combining stage depends on those outputs, so it must wait until the required regional results are available before completing its work.

Q3. A student divides a payment program into four tasks: validate an account, debit it, credit another account, and record the transaction. The student runs all four simultaneously without checking their dependencies. What is the design flaw?

A.The tasks are too small to be represented by threads
B.A multicore processor cannot execute financial software
C.The student assumed the tasks were independent without analyzing required ordering and shared data ✅
D.Every task must execute on the same core
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The flawed step is treating all activities as independent. Account validation and balance updates may have ordering and data dependencies; the designer must identify those relationships and coordinate tasks before running them concurrently.

Q4. A video service decodes each frame independently before sending frames to a later stage. Which decomposition is most likely to expose parallel work without changing the required output order?

A.Decode every frame serially because the final video is ordered
B.Let each decoder overwrite one shared frame buffer
C.Run the final encoding stage before decoding begins
D.Assign distinct frames or frame ranges to independent decoding tasks and preserve ordering when outputs are assembled ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Independent frames can be decoded concurrently because their computations need not depend on one another. The application must still preserve the required frame sequence when collecting results for later processing or encoding.

Q5. Four workers receive jobs that take 5 ms, 5 ms, 5 ms, and 25 ms. All start together on separate cores. Ignoring overhead, when can the whole batch finish?

A.25 ms, because completion is determined by the slowest worker ✅
B.10 ms, because the average job time is 10 ms
C.15 ms, because three workers finish before the fourth
D.40 ms, because all four job times must be added
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The workers run concurrently, so their durations are not added. The batch finishes when the longest job completes: max⁡(5,5,5,25)=25\max(5,5,5,25)=25 ms. Unequal assignments leave three cores idle while the final worker continues.

Q6. A service measures throughput as worker count and completed requests per second: (1, 40) ; (2, 72) ; (3, 91) ; (4, 95) ; (5, 95). What does the pattern suggest?

A.Each additional worker contributes the same throughput increase
B.Throughput falls as soon as more than one worker is used
C.The workload is approaching a bottleneck, so adding workers beyond four gives no measured gain ✅
D.Five workers are required to achieve any parallel execution
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Throughput rises rapidly at first, then changes from 91 to 95 and remains at 95. The plateau suggests a bottleneck or saturation point; extra workers add no measured throughput under this workload.

Q7. A program has 20 percent serial work and 80 percent parallel work. Ignoring overhead, what speedup is possible on four cores?

A.1.25 times
B.2.5 times ✅
C.3.2 times
D.4 times
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Amdahl reasoning gives speedup as 1/(S+(1−S)/N)1/(S+(1-S)/N). With S=0.20S=0.20 and N=4N=4, the result is 1/(0.20+0.80/4)=1/0.40=2.51/(0.20+0.80/4)=1/0.40=2.5, not fourfold speedup.

Q8. A developer creates 10,000 threads for tiny independent calculations, each taking only a few microseconds. Which change is most likely to improve efficiency?

A.Increase the number of threads until every calculation has its own thread
B.Force all threads to run on one core to avoid coordination
C.Copy the entire process address space for every calculation
D.Group small calculations into larger tasks so useful work outweighs creation and scheduling overhead ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The original design makes management overhead large relative to useful computation. Grouping tiny operations into coarser tasks reduces thread creation and scheduling costs while retaining enough independent work for multiple cores.

Q9. A four-stage video pipeline has measured stage times of 8 ms, 5 ms, 14 ms, and 6 ms per frame. Which stage limits steady-state throughput if each stage handles one frame at a time?

A.The 8 ms stage
B.The 5 ms stage
C.The 14 ms stage ✅
D.The 6 ms stage
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: In a pipeline with one unit of capacity per stage, the slowest stage determines the maximum steady-state rate. The 14 ms stage takes longer than the others and therefore limits how quickly frames can pass through.

Q10. A profiling chart records core count and speedup: (1, 1.0) ; (2, 1.7) ; (4, 2.8) ; (6, 3.3) ; (8, 3.5). Which conclusion is justified?

A.Speedup is linear because every added core increases performance
B.The program becomes slower whenever more than four cores are used
C.Eight cores provide exactly eight times the single-core performance
D.Additional cores still help, but diminishing returns indicate limits such as serial work or coordination overhead ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Speedup increases from 1.0 to 3.5, but successive gains become smaller. This is diminishing return rather than linear scaling, consistent with serial portions, synchronization, memory limits, or coordination costs.

Q11. A graphics workload assigns 100 tasks to four workers, but one worker receives 70 tasks while each other worker receives 10. What is the most direct consequence?

A.The application must stop using multiple cores
B.The heavily loaded worker delays completion while other workers become idle ✅
C.The three lightly loaded workers automatically take over the first worker tasks
D.The total amount of computation is reduced to 30 tasks
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Unequal task assignment creates a straggler. The three lightly loaded workers finish early and wait while the worker with 70 tasks continues, so the batch completion time is governed by the overloaded worker.

Q12. A program sums an array of 1,000,000 integers using four threads. Which data partition is simplest when all elements are independent?

A.Give each thread a disjoint contiguous range of approximately 250,000 elements ✅
B.Make every thread sum the entire array and overwrite one shared total
C.Give all four threads the first 250,000 elements
D.Assign elements randomly while allowing multiple threads to update the same partial sum without coordination
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Disjoint contiguous ranges divide the input evenly and avoid overlapping element ownership. Each thread can calculate a private partial sum, after which the results are combined using a controlled reduction.

Q13. A database query partitions records among four cores, but two workers repeatedly update the same shared counter for every record. Which design change most directly reduces contention on that counter?

A.Increase the counter update frequency so cache lines remain active
B.Use one private partial counter per worker and combine them after processing ✅
C.Make every worker update the counter while holding a global lock for the full query
D.Duplicate the entire database for each worker
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Private partial counters avoid repeated simultaneous updates to one shared location. Each worker accumulates locally, and a final reduction combines the values, reducing synchronization and cache-coherence traffic during the main computation.

Q14. Two cores frequently modify different variables that happen to occupy the same cache line. Profiling shows heavy cache-line transfers, but the variables are logically independent. What is the likely problem?

A.A data race that necessarily corrupts both variables
B.Deadlock caused by the cache controller
C.False sharing that creates unnecessary cache-coherence traffic ✅
D.External memory fragmentation between the variables
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: False sharing occurs when independent variables occupy one cache line and different cores modify them. Cache coherence transfers ownership of that line even though the variables do not logically conflict, reducing performance without necessarily causing a data race.

Q15. A student reports that false sharing directly explains why a protected shared balance occasionally becomes numerically corrupted. Which correction is technically sound?

A.False sharing is a memory-allocation failure that resets values
B.False sharing is another name for deadlock
C.False sharing makes mutexes release their locks early
D.False sharing usually harms performance; corruption instead requires a correctness defect such as an unsynchronized conflicting access ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The flawed diagnosis confuses a performance problem with a correctness failure. False sharing causes unnecessary cache-line movement; a corrupted balance suggests a race, invalid update, or another defect in the synchronization logic.

Q16. A multicore processor gives each core a private cache while several cores access shared memory. What is the purpose of a cache-coherence protocol?

A.To ensure cores can never cache the same memory block
B.To keep cached copies consistent when one core modifies shared data ✅
C.To eliminate the need for main memory
D.To guarantee that every thread executes in source-code order
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Private caches reduce memory access time, but cached copies can become stale when another core writes the same location. Coherence protocols coordinate copies so cores observe a consistent value for shared memory operations.

Q17. In a parallel image pipeline, stage B uses the output produced by stage A for the same image tile. What must the program do?

A.Allow B to run before A because both stages are on separate cores
B.Copy unrelated tiles repeatedly until B finishes
C.Synchronize the stages so B reads the tile only after A has produced its output ✅
D.Remove the dependency by assigning both stages the same thread identifier
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Stage B depends on data produced by stage A, so running B too early can expose incomplete or invalid input. A synchronization or dependency mechanism must ensure the required output is ready before consumption.

Q18. Two threads increment a shared counter from 10 using separate read, add, and write instructions. Both read 10 before either writes. What final value can result after both write their incremented values?

A.11, because both threads can write 11 and one update is lost ✅
B.12, because each thread contributes one increment
C.10, because simultaneous reads cancel the writes
D.13, because each thread increments the other thread result
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Both threads read 10 and independently calculate 11. If each writes 11, the second write does not add another increment, so the final value is 11 rather than the expected 12.

Q19. A shared request counter is updated by many server threads. Which operation most directly prevents lost increments while keeping the increment itself indivisible?

A.A normal load followed later by a normal store
B.A thread-local copy that is never combined
C.A delay inserted between reading and writing
D.An atomic fetch-and-add operation on the shared counter ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: An atomic fetch-and-add performs the read-modify-write as one indivisible operation. Concurrent increments therefore do not overwrite one another, unlike separate ordinary reads and writes that can interleave. It protects the update itself.

Q20. A developer protects a shared data structure with a mutex. Which rule correctly describes ownership of that mutex?

A.Any thread may unlock it, even if it did not acquire it
B.The thread that acquires the mutex is responsible for releasing it according to the mutex contract ✅
C.A mutex counts how many buffer slots are available
D.A mutex guarantees that waiting threads never experience starvation
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A mutex provides mutual exclusion with ownership semantics: the thread that locks it is expected to unlock it. A semaphore instead represents permits or a count and does not have the same ownership rule.

Q21. A producer-consumer queue has capacity 8. Which synchronization arrangement correctly represents available and occupied slots while protecting queue updates?

A.Initialize both semaphores to 8 and omit mutual exclusion
B.Use one binary semaphore initialized to 0 for both empty and full counts
C.Use an empty-slot count initialized to 8, a full-slot count initialized to 0, and a mutex for queue modifications ✅
D.Use a mutex initialized to 8 and a counting semaphore initialized to 0
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The empty count starts at the buffer capacity, 8, while the full count starts at 0. A mutex separately protects the queue structure, because counting available slots does not make concurrent queue modifications safe.

Q22. A thread checks a condition variable predicate, finds it false, and is preempted before calling wait. Another thread changes the predicate and signals. What role does the associated mutex play when used correctly?

A.It makes checking the predicate and entering the wait operation coordinated, preventing a missed wakeup ✅
B.It forces the signaling thread to terminate
C.It prevents the predicate from changing after initialization
D.It converts the condition variable into a counting semaphore
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The mutex protects the predicate check and is released atomically as the waiter enters the wait operation. This closes the gap in which a signal could otherwise occur after the check but before waiting.

Q23. Thread A always acquires L1 before L2, while Thread B always acquires L2 before L1. Both need both locks. Which design rule prevents this circular-wait pattern?

A.Allow each thread to retry the opposite lock indefinitely
B.Require all threads to acquire locks in one consistent global order ✅
C.Increase the number of processor cores
D.Release both locks whenever either thread is preempted
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The original ordering permits each thread to hold one lock while waiting for the other. A consistent global acquisition order prevents this circular wait and therefore removes this deadlock pattern.

Q24. A spinlock protects a short critical section, but many cores contend for it while the lock holder is descheduled. Why can performance collapse?

A.Waiting threads automatically execute the protected operation twice
B.Compare-and-swap stops being atomic when contention rises
C.Spinning threads consume processor time and repeatedly generate cache-coherence traffic instead of sleeping ✅
D.The lock permanently changes from a mutex into a semaphore
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Under heavy contention, waiters repeatedly poll the lock and consume CPU cycles while generating memory traffic. If the owner is not running, spinning can delay release and waste resources that a blocking lock would preserve.

Q25. Two threads repeatedly detect that the other is about to acquire a resource, back off, and then retry at nearly the same time. Neither is blocked, but useful work never completes. What is this condition?

A.Deadlock
B.Starvation caused by memory fragmentation
C.Priority inversion
D.Livelock ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Livelock occurs when threads remain active and repeatedly react to one another without completing useful work. Deadlocked threads are blocked, whereas livelocked threads continue changing state or retrying without forward progress.

Q26. A lock-free stack uses compare-and-swap. A thread reads pointer value A, another thread changes it to B and later back to A, and the first thread CAS succeeds. What issue has occurred?

A.Priority inversion
B.The ABA problem, because the value appears unchanged despite an intervening modification ✅
C.False sharing, because two variables occupy one cache line
D.A lost wakeup on a condition variable
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The first thread sees A both before and after another thread changes the state through B. Compare-and-swap compares the current value, not its history, so a version tag or another reclamation strategy may be needed.

Q27. A parallel program passes tests on every run with one core but occasionally fails with four cores. Which explanation should guide debugging first?

A.The additional cores must be defective
B.The compiler necessarily changes arithmetic precision on multicore machines
C.Different thread interleavings may expose a race or missing synchronization that sequential runs did not reveal ✅
D.A program that passes once on one core is proven correct
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Multicore execution permits many interleavings that may not occur in a particular single-core test. Intermittent failures therefore warrant examination of shared state, ordering assumptions, and synchronization rather than blaming core count.

Q28. A developer reproduces a race only when a logging statement is removed. What is the best interpretation of this behavior?

A.Logging changes execution timing and may hide or expose a timing-sensitive interleaving without fixing the race ✅
B.The logging statement is a required synchronization primitive
C.Removing output statements changes the number of physical cores
D.The race must be caused by disk fragmentation
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Logging adds instructions and can alter thread timing. A race may disappear or appear when the schedule changes, but this timing effect does not establish correctness; the shared access still needs proper synchronization.

Q29. A test plan for a multicore application checks only one successful run with a fixed workload. Which improvement most directly addresses the difficulty of concurrent testing?

A.Use fewer test cases so the scheduler has fewer choices
B.Disable all synchronization to expose the fastest path
C.Test only when every thread starts in the same order
D.Repeat tests under varied workloads and scheduling conditions, and use tools that detect races and unsafe accesses ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Concurrent defects may depend on rare timing and interleaving. Repeated tests with varied workloads, timing, and scheduling conditions increase coverage, while race-detection tools can identify unsafe shared-memory accesses. This makes testing more systematic.

Q30. A production system reports incorrect account balances. The code uses a mutex around every balance update, but a diagnostic path reads balances without acquiring the mutex. What is the strongest conclusion?

A.The mutex is ineffective because it cannot protect any data on multicore hardware
B.The unprotected diagnostic read can race with updates; all conflicting accesses must follow a consistent synchronization rule ✅
C.The problem must be false sharing rather than a data race
D.The operating system should disable the other processor cores
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The flawed design protects writes but leaves a conflicting read outside the synchronization protocol. A mutex helps only when every access that can conflict follows the same locking discipline or an equivalent safe atomic scheme.

Q31. A benchmark records lock-contention level and completed operations per second: (0, 1200) ; (1, 1050) ; (2, 800) ; (3, 510) ; (4, 300). Which trend is most strongly indicated?

A.More contention improves throughput because more threads are waiting
B.Throughput is independent of contention level
C.Throughput falls as contention rises, indicating coordination or serialization costs are limiting useful parallel work ✅
D.The data prove that the program has no shared state
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Throughput declines from 1200 to 300 operations per second as contention increases. The pattern indicates that coordination, lock waiting, or serialized access is consuming more time and limiting parallel progress.

Q32. Two related components run as threads in one process and exchange small records thousands of times per second. Why can this arrangement reduce communication overhead compared with separate processes using message passing?

A.Threads can access shared objects through the same address space without packaging every exchange as an interprocess message ✅
B.Threads never need synchronization when accessing shared records
C.Separate processes cannot exchange records on the same computer
D.Shared-memory communication guarantees that every update is immediately visible without coherence mechanisms
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Threads in one process can exchange records through shared memory, avoiding some message packaging and transfer costs. This does not remove synchronization needs, and separate processes can also communicate through explicit mechanisms.

Q33. A developer uses double-checked locking to initialize a shared object. On a weakly ordered multicore system, another thread observes a non-null reference before construction writes are safely published. What is the underlying issue?

A.The second null check always destroys the initialized object
B.A mutex cannot protect any initialization code on a multicore processor
C.Unsafe publication and memory reordering can let a thread observe a partially initialized object ✅
D.The operating system changes the object reference after every context switch
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The flawed assumption is that observing a non-null reference proves construction is complete. Without appropriate synchronization and memory-order guarantees, another core may see the reference before the object initialization writes become visible.

🔗 Related Topics (MCQs)