Skip to content
BytePatterns

Threads vs Processes

Concurrency: lesson 1 of 10

Shared memory, or a wall between you.

Lesson 1 of 10 · 4 min

Threads vs Processes

Step 1 of 9

A process owns its memory. Threads live inside one process and share every byte of it.

The Idea

A process owns its memory. Threads live inside one process and share that memory, so starting one is cheap and handing over data costs nothing. Processes are walled off: sending work means copying it, but one crash cannot corrupt a sibling.

Real-World Example

Housemates share a kitchen; neighbours have their own. Housemates pass the salt across the counter in a second, and one of them leaving the gas on ruins everyone's evening. Borrowing sugar next door means packaging it and walking it to the door.

The Tradeoff

Threads are cheap and fast to coordinate, and every shared variable is now a bug waiting for the wrong interleaving. Processes buy isolation with memory duplication and serialisation on every message. In Python the GIL settles most arguments: I/O-bound work wants threads, CPU-bound work wants processes.

Your turn

Put the steps in the right order.

  1. Each child runs in its own interpreter, on its own core
  2. The parent process starts, holding the whole input batch
  3. Results are serialised and sent back to the parent
  4. The batch is split and copied into each child process

Mini quiz

1 / 3

Two threads in one process share: