LearnThatStack Ace your next interview
Concurrency & Multithreading · question
Question 3 of 54

Why is creating threads expensive, and roughly how expensive?

beginner
← All Concurrency & Multithreading questions
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.

The biggest cost is the stack. A default thread stack reserves from half a 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 dwarfs the microsecond-scale work you often hand it, so 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 cost is in the constant creation and teardown 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 ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Concurrency & Multithreading One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

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.

Interview lens How interviewers actually use this question

Likely follow-ups

What you can say

  1. Each thread needs its own stack plus kernel bookkeeping, so creating one costs real memory and real time.
  2. When you create a thread, the OS allocates memory, registers the thread with its scheduler, and sets up the cleanup for when it exits.
  3. The biggest piece is the stack, and a default one reserves between half a megabyte and eight megabytes depending on the platform.
  4. So if you spawn thousands of threads, you burn gigabytes of address space on stacks alone.
  5. In wall-clock terms, creating and destroying a thread takes tens of microseconds, which dwarfs the microsecond-scale task you often hand it.
  6. A one-off thread for a long job is fine, but creating one per request under load spends more on setup than on the work, which is why servers reuse threads from a pool.

Weak answers to avoid

  • Says it is slow but gives no numbers The question asks how expensive. Give the half a megabyte to eight megabyte default stack reservation and tens of microseconds to create and destroy a thread.
  • Treats the reserved stack as RAM used Saying each thread uses 8 MB of RAM overstates it. The default stack reserves address space, and the OS commits physical pages only as the stack grows.
  • Blames context switching for creation cost Context switching is a cost of running many threads at once. Creation cost is the stack and kernel setup paid every time a thread starts and exits.
  • Stops at the cost, never mentions pools The point of knowing the cost is what you do about it. Say that per-request spawning spends more on setup than on the task, so servers reuse pooled threads.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Concurrency & Multithreading cheatsheet.

← Back to all Concurrency & Multithreading questions
Pro · $10/mo

47 of 54 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