📝 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.
📝 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 Explanation: The workers run concurrently, so their durations are not added. The batch finishes when the longest job completes: 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?
📖 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?
📖 Explanation: Amdahl reasoning gives speedup as . With and , the result is , 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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.