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.