All questions
Showing of 50What is the difference between concurrency and parallelism?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Concurrency means structuring a program so many tasks can make progress in overlapping time windows. Parallelism means literally running tasks at the same instant on separate cores. A single-core machine can be concurrent but never truly parallel.
A concurrent design interleaves tasks by pausing one and resuming another. This helps when tasks wait on input, network, or disk. Parallelism helps when you have real compute to split across cores.
You can have either without the other. A single-threaded event loop is concurrent, not parallel. A numeric loop spread across eight cores is parallel. Most real systems mix both.
The practical call: reach for concurrency when tasks mostly wait, and parallelism when tasks mostly compute. Confusing them leads to adding cores that never help, or adding threads to work that has no waiting to overlap.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a race condition and why is it so hard to reproduce?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A race condition is a bug where the outcome depends on the timing of two or more threads. When they touch shared data and the order is not controlled, results vary run to run.
Take two threads each reading a counter, adding one, and writing back. If both read the same value before either writes, one increment is lost. The count is wrong only for certain interleavings.
It hides because the bad interleaving is rare. Scheduling is nondeterministic and shifts with load, timing, and the machine. A test can pass thousands of times and still fail in production.
That nondeterminism is exactly why rerunning does not debug a race. You fix it by reasoning about shared state and adding synchronization, not by hunting for the one crash.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Why is creating threads expensive, and roughly how expensive?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Creating a thread is expensive because each one needs its own stack and kernel bookkeeping. The operating system allocates memory, registers the thread with its scheduler, and sets up later cleanup. None of that is free.
The biggest cost is the stack. A default thread stack reserves from one megabyte to eight, depending on the platform. Spawn thousands and you burn gigabytes of address space on stacks alone.
In wall-clock terms, creating and destroying a thread takes tens of microseconds. That sounds tiny, but it dwarfs the microsecond-scale work you often hand it. Per-request spawning spends more on setup than on the task.
This is why servers reuse threads from a pool instead of making one per request. The pain is not the running; it is the constant birth and death under load.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a mutex and how does it stop a race condition?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A mutex (mutual exclusion lock) is a gate that only one thread can hold at a time. A thread locks it before touching shared data and unlocks it when done. Others must wait.
By forcing threads to take turns, a mutex serializes access to a critical section. The lost-update problem vanishes because no two threads read-modify-write the same value at once.
mutex.lock();
counter = counter + 1; // no other thread runs this line now
mutex.unlock();
The cost is real. While one thread holds the lock, others block and do nothing. Hold it too long and you turn parallel work back into sequential work.
So a mutex trades some throughput for correctness. Lock only the shared state, keep the region small, and always release even when errors happen.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a deadlock and what four conditions must all hold?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A deadlock is a standstill where two or more threads each wait for a resource the other holds. None can proceed, so all stay stuck forever. The program hangs without crashing.
All four Coffman conditions must hold at once:
- Mutual exclusion: a resource can be held by only one thread.
- Hold and wait: a thread keeps what it has while waiting for more.
- No preemption: you cannot forcibly take a resource away.
- Circular wait: a cycle of threads each waits on the next.
Break any one and deadlock cannot form. The most common fix targets circular wait by making every thread acquire locks in the same order.
This matters because deadlocks rarely show in testing and freeze real services silently. Knowing the four conditions gives you concrete levers to design them out.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a thread pool and why reuse threads instead of spawning?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A thread pool is a fixed set of worker threads that pull tasks from a shared queue. You submit work; an idle worker picks it up, runs it, then loops back for more. The workers live for the life of the program.
Reusing threads dodges the birth-and-death cost of spawning one per task. That setup, tens of microseconds each, adds up fast under load. Warm threads skip it entirely.
A pool also caps concurrency. With a bounded worker count, you never accidentally launch ten thousand threads and exhaust memory or thrash the scheduler. The queue absorbs bursts instead.
The tradeoff is tuning. Too few workers and tasks wait in the queue; too many and they fight over cores. Size the pool to the workload: roughly core count for compute, higher for I/O-bound work.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How does the JavaScript event loop run async work on one thread?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The JavaScript event loop runs one piece of code at a time on a single thread. It repeatedly takes the next callback from a queue, runs it to completion, then grabs the next. Nothing interrupts a running function.
Async work does not run on that thread. When you start a timer, network request, or file read, the runtime hands it to the system or a background pool. Your thread moves on right away.
When the operation finishes, its callback is placed on a queue. The loop runs it only after the current work returns and the stack is empty. That is why order can surprise you.
This model avoids locks entirely, since only one callback runs at a time. The catch is that any slow synchronous function freezes everything. One blocking loop stalls every pending timer, request, and click.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a critical section and why keep it as short as possible?
How do a semaphore and a mutex differ in purpose?
What is a condition variable and what problem does it solve?
What is an atomic operation and when is one enough?
What is the producer-consumer problem and how is it solved?
Why do race conditions hide in testing but surface in production?
When should you reach for async I/O instead of a thread pool?
What is the difference between a data race and a race condition?
How does lock contention limit throughput as thread count rises?
What is the difference between blocking and busy-waiting for a lock?
How does consistent lock ordering prevent deadlock?
What is livelock and how does it differ from deadlock?
What is starvation, and how does lock fairness reduce it?
What is a read-write lock and when does it actually pay off?
How does compare-and-swap implement a lock-free counter?
Why can one thread miss another thread's writes without synchronization?
What does a volatile or atomic flag guarantee, and what does it not?
How does double-checked locking break without a memory barrier?
How does lock granularity trade contention against overhead?
How do you make a bounded buffer block when full or empty?
What does a thread context switch cost under heavy contention?
Why does async/await not speed up CPU-bound work?
How does a reentrant lock keep a thread from deadlocking itself?
How would you make a shared counter class thread-safe with minimal contention?
What is false sharing and how can it silently destroy parallel throughput?
How does the ABA problem defeat naive compare-and-swap, and how do you fix it?
How would you design a thread pool that avoids deadlock on nested tasks?
How do you detect and recover from a deadlock in a live service?
How would you build a non-blocking queue that scales across many producers?
What breaks in a lock-based cache at a million requests per second?
How do acquire and release memory ordering keep a lock-free algorithm correct?
How would you diagnose a race that appears only under production load?
How do you add backpressure to a producer-consumer pipeline that outpaces consumers?
What goes wrong when a thread pool's work queue grows without bound?
How would you make singleton initialization both safe and nearly lock-free?
How do you prevent priority inversion in a latency-sensitive system?
Why can adding more threads slow a program down, and where is the knee?
How would you review unfamiliar code for concurrency bugs you cannot reproduce?
How would you shard or stripe a lock to cut contention safely?
How do you safely reclaim memory in a lock-free data structure?
What are the failure modes of code that blocks the event loop?
How do you cancel and clean up in-flight async work without leaks or races?
How would you stress-test concurrent code to surface rare interleavings?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Concurrency & Multithreading cheatsheet
- 30-second mental model01
- Race conditions02
- Locks & synchronization primitives03
- Atomics & lock-free04
- Memory visibility05
- Deadlock, livelock, starvation06
- Thread pools & backpressure07
- Event loop (JS / Node)08
- Async vs threads (picking a model)09
- Reviewing concurrent code (checklist)10
- Common pitfalls11
- + 5 more inside
43 of 50 Concurrency & Multithreading answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.