Concurrency interview questions
50 questions from real iOS interviews. Topics: GCD, OperationQueue, async/await, actors, Sendable, data races.
- ConcurrencyShort answer
GCD basics
What is GCD (Grand Central Dispatch), and why do you hand work to a queue instead of creating threads yourself?
#gcd #dispatch-queue #thread-pool #serial
- ConcurrencyMultiple choice
sync/async vs serial/concurrent
Which of the following statements about sync/async and serial/concurrent queues are correct? Select all that apply.
#sync #async #serial #concurrent
- ConcurrencyShort answer
Main thread and UI
In a UIKit screen you set label.text = result inside a network response callback, and sometimes the screen updates late or not at all. What's causing that?
#main-thread #ui #main-actor #runloop
- ConcurrencyMultiple choice
await vs async let
In Swift Concurrency, if fetchProfile() and fetchFeed() each take 1 second, which statement about the total time of these two snippets is correct? …
#async-await #async-let #parallel #sequential
- ConcurrencyMultiple choice
iOS concurrency tools
Which of the following are appropriate ways to run work in the background (concurrency) on iOS? Select all that apply.
#thread #gcd #operationqueue #async-await
- ConcurrencyShort answerOracleinterview report
Choosing concurrency tools
A new iOS feature needs a network result shared across several screens, and the UI has to update too. What role would you give each of Swift Concurrency's asyn…
#swift-concurrency #async-await #actor #mainactor
- ConcurrencyMultiple choice
Serial queue self-sync
You run this GCD code inside viewDidLoad of a UIKit view controller (main thread). What happens? …
#deadlock #sync #main-queue #serial
- ConcurrencyShort answer
GCD vs OperationQueue
You're building an image pipeline: download, resize, then save to the disk cache, and when the user scrolls you need to cancel work in progress. Would you pick…
#operationqueue #operation #gcd #dependency
- ConcurrencyMultiple choice
QoS classes
The user tapped a button and is waiting for the result, and you want to send JSON parsing to a GCD background queue. Which QoS fits best?
#qos #quality-of-service #priority #global-queue
- ConcurrencyShort answer
Race conditions
This code gets called from several threads, and count comes out lower than expected. Can you explain why at the CPU level? …
#race-condition #data-race #lock #serial-queue
- ConcurrencyMultiple choice
Barrier and reader-writer
In this cache built on a GCD concurrent queue, which statement about the role of the .barrier flag is correct? …
#barrier #concurrent-queue #reader-writer #gcd
- ConcurrencyShort answer
Combining async work
When a screen appears you call three APIs in parallel, profile, feed, and notifications, and you have to render the UI once when all of them finish. How would …
#dispatchgroup #semaphore #async-let #taskgroup
- ConcurrencyMultiple choice
Semaphores and mutexes
Which of the following statements about DispatchSemaphore and mutexes (NSLock, Mutex) are correct? Select all that apply.
#semaphore #mutex #lock #synchronization
- ConcurrencyShort answer
How async/await works
In Swift Concurrency, what actually happens when execution hits an await, and how is that different from blocking a thread?
#async-await #suspension #continuation #cooperative-thread-pool
- ConcurrencyShort answer
How Task runs
In Swift Concurrency, when you create a Task { }, when and where does that code run?
#task #unstructured #detached #inheritance
- ConcurrencyMultiple choice
Combine operators and schedulers
You want to call the API once, 300ms after typing stops, instead of on every keystroke in a search field, and receive the result on the main thread. Which Comb…
#combine #debounce #throttle #scheduler
- ConcurrencyShort answer
Run loop modes
While the user scrolls, an on-screen countdown Timer stops, and when scrolling ends it catches up all at once. From the run loop's point of view, what's the ca…
#runloop #timer #main-thread #runloop-mode
- ConcurrencyShort answerWalmartinterview report
class vs actor
In Swift, what's the difference between a class and an actor?
#actor #mainactor #isolation #class
- ConcurrencyShort answerCapital One
Combine zip vs combineLatest
Write a Combine pipeline that sends two different network requests (user profile, account list) at the same time and emits a result once, only when both have c…
#combine #zip #combinelatest #network
- ConcurrencyMultiple choiceXiaohongshu
Concurrent queue self-sync
What does this GCD code print? And does every call to queue.async create a new thread? …
#gcd #concurrent #sync #thread-pool
- ConcurrencyShort answerDiDi
Dependent work, priority inversion
You have independent pieces of work A, B, and C. C must run only after both A and B have finished, the order of A and B doesn't matter, and they don't nest ins…
#dispatchgroup #barrier #operationqueue #async-let
- ConcurrencyShort answerFlipkart
Search debounce
Calling the API on every keystroke in a search field floods it with requests. Can you implement a debounce with GCD yourself, so the call only fires when there…
#debounce #dispatchworkitem #task #cancellation
- ConcurrencyShort answerCRED
Leaving a loading screen
When the user enters the detail screen, it calls an API like this and shows the data. … The interviewer asks: "What happens if the user taps back before the re…
#cancellation #task #weak-self #timeout
- ConcurrencyShort answerGrindrinterview report
Offloading the main thread
A UIKit screen with image conversion and API response handling stutters while scrolling. Which work would you move off the main actor?
#mainactor #background-work #uikit #threading
- ConcurrencyShort answerZalandointerview report
Shared cache data race
Several image requests read and write the same in-memory cache dictionary at the same time. It crashes now and then, and the logs show the same URL downloaded …
#actor #data-race #cache #inflight
- ConcurrencyShort answerSquare
Structured cancellation
When the search query changes, the previous search's network, decoding, and image work all have to stop. How would you structure the task tree using cancellati…
#cancellation #structured-concurrency #task-group #search
- ConcurrencyShort answerIntuitinterview report
Latest response wins
On a tax summary screen, changing the filter quickly makes several API requests finish almost at once. To make sure only the result for the last filter chosen …
#stale-response #cancellation #state #concurrency
- ConcurrencyShort answerHSBCinterview report
async let vs TaskGroup
A banking app's home screen has to fetch independent account, card, and notification data at the same time. Between async let and TaskGroup, which would you pi…
#async-let #taskgroup #fanout #error-handling
- ConcurrencyShort answerRazorpay
DispatchGroup fan-out
In a callback-based payments app, you have to build a payment summary after three independent APIs have all finished. Where would you put DispatchGroup's enter…
#dispatchgroup #callbacks #fanout #errors
- ConcurrencyShort answerApple
Diagnosing deadlocks
QA reports that the app sometimes freezes completely with no crash log. If you suspect a deadlock, in what order would you track down the cause?
#deadlock #debugging #lldb #lock-ordering
- ConcurrencyMultiple choice
Structured concurrency
Which of the following statements about structured concurrency (async let, TaskGroup) are correct? Select all that apply.
#structured-concurrency #async-let #taskgroup #cancellation
- ConcurrencyMultiple choice
Sendable conformance
Under Swift 6 strict concurrency, which of the following are treated as Sendable (or adopt it automatically) with no extra work? Select all that apply.
#sendable #swift-6 #strict-concurrency #value-type
- ConcurrencyShort answer
Swift 6 migration
You've been asked to move a large app written with completion handlers and GCD to Swift 6 strict concurrency. In what order would you do it?
#swift-6 #strict-concurrency #migration #completion-handler
- ConcurrencyShort answer
MainActor isolation
In Swift Concurrency, what's the difference between putting @MainActor on a whole view model class and putting it on specific methods only?
#mainactor #global-actor #nonisolated #isolation
- ConcurrencyShort answer
Thread Sanitizer
How does Thread Sanitizer actually catch data races?
#tsan #thread-sanitizer #data-race #debugging
- ConcurrencyShort answerSnapinterview report
Async network client design
Design the API of an async network client that several screens use at the same time. It must never block the main thread, and it needs deduplication of identic…
#design #network-client #async #cancellation
- ConcurrencyShort answer
Canceling delayed work
You scheduled DispatchQueue.main.asyncAfter(deadline: .now() + 2) { showTooltip() }, and if the user leaves the screen within 2 seconds it has to be canceled. …
#dispatchworkitem #asyncafter #cancellation #task-sleep
- ConcurrencyShort answerPayPal
Completion handlers to async
You have an old networking layer built on completion handlers, called from hundreds of places across the app. How would you move it to async/await without brea…
#async-await #continuation #migration #cancellation
- ConcurrencyShort answerPhonePe
Ordered concurrent downloads
You're given an array of image ids [3, 1, 2]. Download each image concurrently, but display them on screen in id order (1, 2, 3). How would you do that with Sw…
#taskgroup #structured-concurrency #ordering #cancellation
- ConcurrencyMultiple choiceZomato
Nested queue output
You run this GCD code on the main thread. What's the output? …
#gcd #main-queue #sync #deadlock
- ConcurrencyMultiple choiceKuaishou
Serial vs concurrent sync
You call this function, which takes a GCD queue, from the main thread. About how many seconds until it returns? Answer for (1) a serial queue and (2) a concurr…
#gcd #serial #concurrent #sync
- ConcurrencyMultiple choiceNetEase
Lock-free increment range
Five threads each run count += 1 20 times on a shared variable count (initially 0), with no lock. When they've all finished, what range of values can count hav…
#race-condition #data-race #atomicity #lock
- ConcurrencyShort answerByteDance
Multi-reader single-writer queue
You want a property that several threads can read at the same time while writes happen one at a time. Back in the Objective-C days there was a pattern of dispa…
#gcd #barrier #reader-writer #objective-c
- ConcurrencyShort answerMicrosoft
Dictionary cache thread safety
In a message list screen, each cell downloads its profile image asynchronously and caches it in a [String: UIImage] dictionary. With several threads reading an…
#thread-safety #dictionary #nscache #lock
- ConcurrencyShort answerDropbox
Merging same-URL downloads
In a photo grid, several cells request the same photo URL at the same time, but the network download must happen only once. How would you keep in-flight Tasks …
#actor #image-download #deduplication #task
- ConcurrencyShort answer
Actor reentrancy
This image cache actor built with Swift Concurrency sometimes sends two network requests for the same key. The actor protects its state, so why does this happe…
#actor #reentrancy #isolation #await
- ConcurrencyMultiple choice
Cooperative cancellation
In this Swift Concurrency code, which statement about what actually happens right after t.cancel() is correct? …
#cancellation #task #checkcancellation #task-sleep
- ConcurrencyShort answerAmazon
Designing a dispatch queue
Design a MyQueue of your own without GCD. Submitting a closure with async(_:) should run it on a background thread pool, it should support serial and concurren…
#design #queue #thread-pool #condition-variable
- ConcurrencyShort answer
Real-time pipeline
You're building an app that applies real-time filters to the camera preview. It has to hold 60fps while staying memory safe (no buffer leaks, no contention). W…
#realtime #video #60fps #backpressure
- ConcurrencyShort answer
Swift 6 singleton build
The take-home app you submitted has a singleton ImageCache created with static let shared (with var storage: [URL: UIImage] inside) that several screens read a…
#swift6 #strict-concurrency #sendable #singleton