← Lessons

quiz vs the machine

Silver1050

Concurrency

The Process vs Thread

Why threads share an address space while processes stay isolated, and what that buys each model.

4 min read · intro · beat Silver to climb

Two ways to run code at once

An operating system runs concurrent work as either separate processes or multiple threads inside one process. Both let the machine make progress on more than one task, but they differ in what they share.

What a process owns

A process is an isolated unit of execution. It has its own address space, its own file handles, and its own view of memory. Two processes cannot read each other's memory by accident, so a crash in one rarely takes down another. The cost is that talking between processes needs explicit channels like pipes or sockets.

What threads share

A thread lives inside a process and shares that process's address space with its sibling threads. Threads each get their own stack and registers but reach the same heap and globals.

  • Sharing makes communication cheap because threads touch the same memory directly.
  • Sharing also makes bugs easy, since two threads writing the same variable can race.

Threads are cheaper to create and switch between than processes because the OS reuses the shared context.

Key idea

Processes isolate memory for safety at higher communication cost, while threads share an address space for cheap communication at the price of races.

Check yourself

Answer to earn rating on the learn ladder.

1. What do sibling threads in one process share?

2. Why is communication between two processes more expensive than between two threads?