LearnThatStack Ace your next interview
Computer Science Fundamentals
Concurrency & Multithreading.
Change topic Change
Practice · Questions

All questions

Showing of 50
Beginner 12
01

What is the difference between concurrency and parallelism?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is a race condition and why is it so hard to reproduce?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

Why is creating threads expensive, and roughly how expensive?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is a mutex and how does it stop a race condition?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is a deadlock and what four conditions must all hold?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What is a thread pool and why reuse threads instead of spawning?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How does the JavaScript event loop run async work on one thread?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What is a critical section and why keep it as short as possible?

Part of Pro
09

How do a semaphore and a mutex differ in purpose?

Part of Pro
10

What is a condition variable and what problem does it solve?

Part of Pro
11

What is an atomic operation and when is one enough?

Part of Pro
12

What is the producer-consumer problem and how is it solved?

Part of Pro
Intermediate 18
13

Why do race conditions hide in testing but surface in production?

Part of Pro
14

When should you reach for async I/O instead of a thread pool?

Part of Pro
15

What is the difference between a data race and a race condition?

Part of Pro
16

How does lock contention limit throughput as thread count rises?

Part of Pro
17

What is the difference between blocking and busy-waiting for a lock?

Part of Pro
18

How does consistent lock ordering prevent deadlock?

Part of Pro
19

What is livelock and how does it differ from deadlock?

Part of Pro
20

What is starvation, and how does lock fairness reduce it?

Part of Pro
21

What is a read-write lock and when does it actually pay off?

Part of Pro
22

How does compare-and-swap implement a lock-free counter?

Part of Pro
23

Why can one thread miss another thread's writes without synchronization?

Part of Pro
24

What does a volatile or atomic flag guarantee, and what does it not?

Part of Pro
25

How does double-checked locking break without a memory barrier?

Part of Pro
26

How does lock granularity trade contention against overhead?

Part of Pro
27

How do you make a bounded buffer block when full or empty?

Part of Pro
28

What does a thread context switch cost under heavy contention?

Part of Pro
29

Why does async/await not speed up CPU-bound work?

Part of Pro
30

How does a reentrant lock keep a thread from deadlocking itself?

Part of Pro
Expert 20
31

How would you make a shared counter class thread-safe with minimal contention?

Part of Pro
32

What is false sharing and how can it silently destroy parallel throughput?

Part of Pro
33

How does the ABA problem defeat naive compare-and-swap, and how do you fix it?

Part of Pro
34

How would you design a thread pool that avoids deadlock on nested tasks?

Part of Pro
35

How do you detect and recover from a deadlock in a live service?

Part of Pro
36

How would you build a non-blocking queue that scales across many producers?

Part of Pro
37

What breaks in a lock-based cache at a million requests per second?

Part of Pro
38

How do acquire and release memory ordering keep a lock-free algorithm correct?

Part of Pro
39

How would you diagnose a race that appears only under production load?

Part of Pro
40

How do you add backpressure to a producer-consumer pipeline that outpaces consumers?

Part of Pro
41

What goes wrong when a thread pool's work queue grows without bound?

Part of Pro
42

How would you make singleton initialization both safe and nearly lock-free?

Part of Pro
43

How do you prevent priority inversion in a latency-sensitive system?

Part of Pro
44

Why can adding more threads slow a program down, and where is the knee?

Part of Pro
45

How would you review unfamiliar code for concurrency bugs you cannot reproduce?

Part of Pro
46

How would you shard or stripe a lock to cut contention safely?

Part of Pro
47

How do you safely reclaim memory in a lock-free data structure?

Part of Pro
48

What are the failure modes of code that blocks the event loop?

Part of Pro
49

How do you cancel and clean up in-flight async work without leaks or races?

Part of Pro
50

How would you stress-test concurrent code to surface rare interleavings?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Concurrency & Multithreading? Send them this set.
Pro · $10/mo

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.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git