🎓 BookMCQ
← Back to 4. Threads in Operating System

📝 Grand Central Dispatch in operating system (33 MCQs)

Task-Based Concurrency in Apple's Grand Central Dispatch

Grand Central Dispatch (GCD) is Apple's concurrency technology for managing asynchronous tasks through dispatch queues. Rather than requiring applications to create and manage individual threads for every operation, developers submit blocks of work to queues. The system manages execution using available worker threads and processor resources, supporting concurrent application design within Apple's operating system environments.

Why Dispatch Queues Simplify Thread Management

Manual thread creation and coordination become difficult when applications contain many short or independent operations. Unrestricted thread creation can waste memory and processor time, while direct thread management complicates scheduling. GCD separates task submission from execution management, allowing the system to coordinate worker resources and schedule eligible work according to queue properties.

Serial and Concurrent Queues with Dispatch Blocks

A dispatch block represents a unit of work submitted to a dispatch queue. A serial queue executes submitted blocks in order, with no overlapping execution on that queue. A concurrent queue allows multiple blocks to execute concurrently, subject to available resources. Dispatch functions and synchronization facilities coordinate submission, execution, and completion.

Submitting Three Tasks to Different Dispatch Queues

Suppose an application submits three independent image-processing blocks to a concurrent queue. The system can schedule eligible blocks on available worker threads, potentially executing them on separate cores. If the same blocks enter a serial queue, they execute one after another in submission order. The queue type therefore influences execution ordering and concurrency.

Worker Efficiency, Queue Ordering, and Synchronisation

GCD simplifies asynchronous programming, reduces direct thread-management responsibilities, and supports efficient execution in Apple applications. Serial queues help preserve operation order, while concurrent queues expose parallel work. However, blocked tasks, excessive synchronisation, and shared-state races can reduce throughput. Developers must avoid assumptions that concurrent queue tasks always execute simultaneously or in a predictable completion order.

Misconceptions About Dispatch Queue Execution

'A dispatch queue is always a dedicated operating system thread' is incorrect because queues manage tasks rather than representing individual threads. 'A concurrent queue guarantees simultaneous execution of every block' is incorrect because available resources determine execution. 'Serial queues execute blocks in random order' is incorrect because their submitted work executes sequentially.

Exam Focus: Serial Queues and Concurrent Task Scheduling

Compare serial and concurrent dispatch queues and trace the submission and execution of multiple blocks. Distinguish task queues from worker threads and explain how GCD reduces manual thread management. Questions may test execution ordering, asynchronous submission, completion handlers, shared-data synchronisation, and the difference between task concurrency and guaranteed parallel execution.

Key Terms of Grand Central Dispatch

  • GCD - Apple's task-based concurrency technology.
  • Dispatch queue - Ordered collection of submitted tasks.
  • Dispatch block - Unit of executable submitted work.
  • Serial queue - Executes tasks sequentially.
  • Concurrent queue - Allows overlapping task execution.
  • Asynchronous execution - Work proceeds without immediate waiting.
12
Easy
10
Medium
11
Hard

📝 All Grand Central Dispatch in operating system MCQs

Q1. A developer needs to execute independent background tasks on Apple platforms without manually creating and managing a separate thread for every task. Which approach best fits this requirement?

A.Create a new operating-system process for every task
B.Use Grand Central Dispatch queues to submit work for runtime scheduling ✅
C.Execute every task inside a single critical section
D.Assign each task permanently to a physical CPU core
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: GCD allows applications to submit units of work to dispatch queues while the system manages execution resources. This reduces the need to create, assign, and destroy a separate thread manually for every task.

Q2. A user interface becomes unresponsive because a developer performs a large image-processing operation synchronously on the main thread. Which change is most appropriate?

A.Move the expensive computation to a suitable background queue and return UI updates to the main queue ✅
B.Increase the number of statements executed on the main thread
C.Place the entire operation inside a synchronous main-queue dispatch
D.Replace image processing with repeated main-thread polling
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Long computation on the main queue delays input handling and screen updates. Moving suitable work to a background queue keeps the interface responsive, while the final interface change should be scheduled on the main queue.

Q3. A developer dispatches a task asynchronously to a queue and immediately reads a result that the task has not yet produced. Occasionally, the application uses an old value. What is the most likely cause?

A.Asynchronous dispatch always executes tasks in reverse order
B.The queue permanently caches all previous return values
C.Background tasks cannot modify shared data
D.The caller assumes completion before the asynchronous task has finished ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Asynchronous submission returns before the submitted block necessarily finishes. Reading its result immediately can therefore use an old value; the program needs a completion handler, group notification, or another valid synchronization mechanism before consuming the result.

Q4. A developer submits three independent calculations to a serial dispatch queue. Their durations are 2, 3, and 4 seconds. Ignoring overhead, what is the minimum total execution time if all must finish on that queue?

A.4 seconds
B.9 seconds ✅
C.6 seconds
D.2 seconds
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A serial queue executes one submitted block at a time. The durations therefore add: 2+3+4=92+3+4=9 seconds, assuming no overhead and that all three calculations execute on that queue in submission order.

Q5. A developer calls a synchronous dispatch operation on the main queue from code already executing on that same queue. The application hangs. What is the best explanation?

A.The main queue automatically rejects every synchronous operation
B.Synchronous dispatch always creates a deadlock on every queue
C.The operation forces the application to create a new process
D.The current execution waits for work that cannot begin until the current execution returns ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Synchronous dispatch blocks the caller until the submitted block completes. On the same serial main queue, the new block cannot run until the current block returns, while the current block is waiting, producing deadlock.

Q6. A developer needs to perform a background download and then update the interface only after the download succeeds. Which design best expresses the dependency without blocking the interface?

A.Perform the download synchronously on the main queue
B.Submit the download asynchronously, then schedule the UI update on the main queue from its completion path ✅
C.Submit the UI update before starting the download
D.Use the main queue for the download and every interface animation
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The download can run asynchronously without blocking the interface. Its completion path can then submit the required update to the main queue, preserving the dependency while ensuring UI work occurs in the appropriate execution context.

Q7. A task group contains independent file-processing jobs with highly variable execution times. The developer wants to avoid assigning every job to a specific thread. Which GCD property is most relevant?

A.Every queue has a permanently assigned worker thread
B.Each submitted block must explicitly choose its physical CPU core
C.The dispatch system schedules queued work using available execution resources ✅
D.GCD requires all jobs to use the main queue
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: GCD separates task submission from low-level thread assignment. Dispatch queues organize work, while the system schedules eligible tasks using managed execution resources, so developers need not assign each variable-duration job to a particular thread.

Q8. A developer submits a long-running task to a global concurrent queue and expects the system to create one new thread dedicated to that task. Which correction is most accurate?

A.Global queues always create a dedicated thread per submitted block
B.Every global queue is a separate operating-system process
C.The task must execute on the main thread regardless of queue selection
D.GCD manages execution resources, and a submitted block is not guaranteed a dedicated thread ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: A global concurrent queue represents work eligible for concurrent execution, not a promise of one dedicated thread per block. The system chooses execution resources, and the thread used for a task is generally not guaranteed.

Q9. A developer puts CPU-intensive work on a concurrent queue. A benchmark records core count and speedup: (1, 1.0) ; (2, 1.7) ; (4, 2.2) ; (6, 2.3) ; (8, 2.3). The interface remains responsive, but total processing time barely improves. Which interpretation is most reasonable?

A.Concurrent queues guarantee linear speedup only for CPU-intensive tasks
B.The workload may be limited by serial dependencies, hardware capacity, or contention ✅
C.The main thread must be executing every background task
D.The queue automatically converts CPU calculations into input/output operations
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Moving CPU-intensive work away from the main thread can improve responsiveness without shortening total computation. Performance still depends on available cores, serial sections, contention, synchronization, memory behavior, and scheduling overhead.

Q10. A developer wants to execute one setup block before several dependent processing blocks on the same serial queue. Which property helps preserve the required sequence?

A.The queue randomly reorders tasks to maximize processor usage
B.The runtime automatically executes the setup block last
C.Serial queue execution preserves submission order for its queued blocks ✅
D.Each block must be converted into a separate process
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A serial dispatch queue executes its submitted blocks one at a time in submission order. Placing setup before dependent processing blocks on the same queue preserves that sequence without requiring each block to manage its own thread.

Q11. A developer needs to execute several independent tasks concurrently but must protect a shared database cache from simultaneous modifications. Which design is generally reasonable?

A.Use a concurrent queue for independent work and serialize cache mutations through a suitable synchronization mechanism ✅
B.Allow all cache writes to proceed simultaneously because GCD manages threads
C.Place every operation on the main queue without considering responsiveness
D.Create an unsynchronized copy of the cache for every task and merge them randomly
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Independent tasks can use a concurrent queue, while cache mutations are protected through a serial queue, lock, or suitable synchronization mechanism. This limits conflicting updates without unnecessarily serializing unrelated computation.

Q12. A task is submitted with a low-priority quality-of-service setting, while another task has a higher-priority setting. Which expectation is most appropriate?

A.The lower-priority task is guaranteed never to execute
B.The higher-priority task must finish first regardless of dependencies
C.Quality-of-service settings permanently bind each task to a specific CPU
D.The system can use priority information when scheduling work, but exact execution order is not guaranteed ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Quality-of-service information communicates relative importance and responsiveness needs. The system may use it when scheduling work, but dependencies, competing activity, and resource availability mean it does not guarantee exact start or completion order.

Q13. A developer dispatches a block asynchronously to a serial queue and immediately waits on a semaphore that the block signals. The developer is already executing on that same serial queue. The application makes no progress. What should be checked first?

A.Whether the queue contains enough comments
B.Whether the waiting code prevents the queued block from executing ✅
C.Whether the block has too many local variables
D.Whether serial queues automatically discard semaphore signals
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A semaphore wait blocks the calling thread. If that thread is needed to execute the queued block that signals the semaphore, neither can progress; redesign the dependency or avoid blocking the queue execution path.

Q14. A developer uses a dispatch group to coordinate four independent downloads and wants to run a final aggregation step after all downloads finish. Which approach best matches this requirement?

A.Wait for only the first download to complete
B.Place all downloads on the main queue and read their results immediately
C.Register a group notification or wait for the group before aggregating ✅
D.Assume the last submitted download always finishes last
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A dispatch group tracks several asynchronous tasks as one unit. The program can wait for the group or register a notification that runs after all associated tasks complete, making it suitable for final aggregation.

Q15. A developer uses dispatch_apply for 100 independent calculations and assumes each iteration executes on a newly created thread. Which statement is most accurate?

A.dispatch_apply invokes the block the specified number of times and waits for all iterations to complete ✅
B.dispatch_apply creates exactly one operating-system thread for every iteration
C.dispatch_apply returns immediately without waiting for any iteration
D.dispatch_apply requires every iteration to use the main queue
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: dispatch_apply invokes the supplied block a specified number of times and waits for all iterations to finish before returning. On a concurrent queue, iterations may overlap, but the block must be safe for concurrent invocation.

Q16. A program submits three blocks to the same concurrent queue. The first block creates a value required by the third block, while the second and third are submitted immediately afterward. What is the main correctness concern?

A.A concurrent queue always executes blocks in reverse submission order
B.The second block must terminate before the first begins
C.The queue converts the third block into a serial operation automatically
D.The third block may run before the first has produced its required value ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: A concurrent queue does not guarantee that a later block waits for an earlier block's result. The program must express the dependency through a serial queue, group, barrier where appropriate, or another synchronization mechanism.

Q17. A developer wants several tasks to execute one after another in a fixed sequence, with each task seeing the previous task's completed changes. Which choice is most direct when all tasks can use the same queue?

A.Submit all tasks to unrelated concurrent queues
B.Use a concurrent queue and assume completion follows submission order
C.Submit the dependent tasks to the same serial queue in the required order ✅
D.Run all tasks simultaneously and inspect results afterward
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A serial queue executes blocks one at a time in submission order. Submitting each dependent task after its prerequisite on that same queue ensures the later task begins only after the earlier block has completed.

Q18. A developer creates a custom serial dispatch queue and assumes it will always execute blocks on the same physical thread. Which assessment is correct?

A.A serial queue guarantees serialized execution, not permanent use of one physical thread ✅
B.Every custom serial queue owns one permanent operating-system thread
C.The queue creates a separate process for each submitted block
D.A serial queue can execute only on the main thread
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A serial queue guarantees serialized execution, not permanent use of one physical thread. The system manages worker threads and may use different execution resources over time, except for queues explicitly bound to a particular thread.

Q19. A developer submits short tasks to a concurrent queue. A benchmark records task count and elapsed time: (1, 12 ms) ; (2, 9 ms) ; (4, 8 ms) ; (8, 11 ms) ; (16, 17 ms). Which experiment is most useful for understanding why larger batches become slower?

A.Increase task count further without measuring any other variable
B.Compare controlled sequential and concurrent runs while measuring overhead, contention, and resource use ✅
C.Assume the concurrent queue is malfunctioning because it is slower at 16 tasks
D.Move every task to the main queue and compare only CPU frequency
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The useful experiment compares controlled sequential and concurrent runs while measuring elapsed time, task durations, contention, and resource use. This reveals whether scheduling overhead or synchronization costs outweigh the concurrency benefit for the workload.

Q20. A program has two independent background operations and one final operation that requires both results. Which coordination pattern best represents this dependency?

A.Start the final operation immediately and read whichever result is available
B.Use a dispatch group to detect completion of both operations before scheduling the final operation ✅
C.Place all operations on separate queues and assume the final one runs last
D.Wait for one operation and ignore the second
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A dispatch group can track both independent operations and notify when all have completed. The final operation can then be scheduled after group completion, ensuring it does not consume either result prematurely.

Q21. A developer uses a dispatch source to monitor repeated events such as a timer firing or a file descriptor becoming ready. Which description best captures its role?

A.It creates a new process whenever an event occurs
B.It guarantees that every event is handled by the main thread
C.It provides a way to receive and process low-level event notifications through dispatch mechanisms ✅
D.It replaces the operating system's entire interrupt-handling system
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A dispatch source coordinates low-level events and delivers event handling through a dispatch mechanism. It can monitor timers, file-system activity, file-descriptor readiness, or signals without requiring an application to poll continuously.

Q22. A background task reports progress at times and percentages: (0 ms, 10%) ; (20 ms, 30%) ; (40 ms, 25%) ; (60 ms, 55%) ; (80 ms, 45%). Updates sometimes show an older percentage. Which design is most robust?

A.Coordinate progress state, discard stale values, and schedule valid interface updates on the main queue ✅
B.Allow every background task to modify the interface directly without coordination
C.Use a concurrent queue and assume percentages are delivered in order
D.Replace progress updates with synchronous waits on the main thread
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Concurrent progress reports can arrive out of order. Protect the progress state as needed, schedule UI changes on the main queue, and discard stale values so an older completion does not overwrite a newer display.

Q23. A developer submits a block asynchronously and releases an object that the block still needs. The release ends that object's lifetime before the block accesses it. What is the primary issue?

A.Dispatch queues never execute blocks after submission
B.Asynchronous work always copies every object deeply
C.The main queue automatically restores released objects
D.The object's lifetime is not guaranteed to cover the block's execution ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Asynchronous blocks may execute after the submitting function returns. Objects and other resources they use must remain valid until execution finishes; ownership rules, capture semantics, and cancellation behavior should preserve that lifetime.

Q24. A developer uses a barrier-style operation on a private concurrent dispatch queue created by the application to protect a shared resource. What is the intended effect?

A.It converts the application into a single operating-system process
B.It permanently prevents all later blocks from executing
C.It establishes an exclusive execution interval relative to other work on that queue ✅
D.It guarantees that every CPU cache is flushed to physical memory
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: On an appropriately created concurrent queue, a barrier runs exclusively relative to other work submitted to that queue, establishing an ordered access interval. It does not protect accesses from unrelated queues or external code.

Q25. A developer submits tasks to a global queue and uses a dispatch group notification targeting the main queue. Why is this arrangement useful for a graphical application?

A.It lets background work proceed while the final interface-related action is scheduled on the main queue ✅
B.It guarantees that background work uses no CPU resources
C.It ensures the completion handler runs before the tasks start
D.It converts the global queue into a serial queue automatically
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The background tasks run without blocking the interface, and the group notification waits for their completion before scheduling a handler on the main queue. This provides a safe point for interface updates after aggregation work finishes.

Q26. A student claims that tasks submitted to a concurrent queue always run in parallel on separate cores. Which response is correct?

A.The claim is true whenever the queue is named concurrent
B.The claim is true only if all tasks are shorter than one millisecond
C.The claim is false only for tasks that perform input/output
D.Concurrent queues permit overlapping execution, but separate-core execution is not guaranteed for every task ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: A concurrent queue permits multiple blocks to be eligible for overlapping execution, but actual parallelism depends on processor availability and scheduling. Tasks may wait or take turns, so separate-core execution is not guaranteed.

Q27. A serial queue processes requests. One request synchronously waits for another request submitted to the same queue. The application stops progressing. Which reasoning best explains the failure?

A.The queue has too many available worker threads
B.The active request blocks the only execution path that can process the queued dependency ✅
C.Serial queues discard requests that depend on earlier work
D.Synchronous waits automatically make every task asynchronous
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A serial queue runs only one block at a time. If the active block synchronously waits for another block queued behind it, that block cannot start until the active one returns, causing deadlock.

Q28. A developer processes a large collection of independent items and collects one result from each iteration. Which design avoids assuming that iterations finish in index order?

A.Append results to an unsynchronized shared array from every task
B.Assume the first submitted iteration must always finish first
C.Store results in predetermined indices or use safe synchronization when collecting them ✅
D.Read the result array as soon as the first iteration completes
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Independent iterations can finish in an order different from their indices. Store each result in its predetermined slot or coordinate updates to a shared collection, then wait for all required iterations before reading results.

Q29. A chart records worker count and throughput for tasks that repeatedly acquire the same lock: (1, 900) ; (2, 720) ; (4, 500) ; (8, 280) ; (16, 150) operations per second. Which change is most worth evaluating?

A.Increase lock acquisition frequency to improve fairness
B.Move every task to the main queue
C.Assume the operating system has stopped scheduling background work
D.Reduce contention by restructuring shared-state access or batching protected operations ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: A shared lock serializes the protected operations, so adding tasks can increase waiting instead of useful work. Restructure shared-state access, reduce lock hold time, or batch updates while preserving correctness.

Q30. A developer wants a task to run after a delay without blocking the current thread. Which approach best fits the requirement?

A.Call sleep on the main thread until the delay expires
B.Schedule the task using an appropriate dispatch timer or delayed dispatch mechanism ✅
C.Create a busy loop that repeatedly checks the clock
D.Synchronously dispatch the delayed task to the current serial queue
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A delayed dispatch operation schedules work for a future deadline and returns without making the current thread wait. The block may execute later than that deadline because scheduling and system load affect actual start time.

Q31. A developer submits a block to a queue and assumes that returning from the submission call means the block has completed. Which distinction is important?

A.Submitting asynchronous work and completing it are different events ✅
B.Every queue submission waits until all previously submitted work has finished
C.Only global queues support asynchronous execution
D.A block is complete as soon as it enters the queue
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Returning from an asynchronous submission means the work was enqueued, not completed. The caller continues while the block may still be pending or running, so a separate completion mechanism is required before using its result.

Q32. A highly parallel pipeline has stage two begin processing each item only after stage one produces that item's data, while unrelated items should overlap. Which design principle is best?

A.Serialize the entire pipeline and prevent any item from overlapping
B.Run stage two immediately and ignore whether stage one's output exists
C.Use a single shared mutable output value for every item
D.Represent per-item dependencies explicitly while allowing independent items to execute concurrently ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Each item's second stage depends on its first-stage output, but different items are independent. Represent per-item dependencies so each item preserves correct ordering while unrelated items can overlap through concurrent scheduling.

Q33. A developer sees that a task submitted to a background queue sometimes runs later than expected when the device is under heavy load. Which explanation is most accurate?

A.Dispatch queues guarantee exact start times only when tasks are CPU-bound
B.Background tasks are never allowed to execute concurrently
C.The queue must have been converted into a serial queue
D.Queue submission does not guarantee immediate execution; scheduling depends on resource availability and system policy ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Submitting a block makes it eligible for execution but does not guarantee immediate scheduling. System load, competing work, priority, and available execution resources can delay its start, so applications should tolerate timing variability.

🔗 Related Topics (MCQs)