What are Processes and Threads?
Processes and threads, told as a story about hands sharing one car versus mechanics working on separate cars.
Tearing down the engine alone takes far too long.One mechanic alone takes far too long.
You could bring in a whole second car instead.Each car needs its own full toolbox and trunk — a lot of overhead.
Threads = many hands in one car; processes = separate cars entirely.Hands in one car share the trunk — a different car can't see into it.
Whether memory (the trunk) is shared is the key difference.A thread runs inside a process — the real unit the scheduler moves.
Two hands sharing the trunk beat setting up separate ones — but a collision ruins the work of both.That's why a shared trunk always needs a synchronization rule.
Process = each its own independent car (independent memory). Thread = several hands working inside the same car, sharing its trunk (memory).
A process is an execution unit with its own OS-allocated memory space — it can't peek directly into another process's memory. A thread is a lighter execution unit living inside a process, sharing its code, data, and heap, while keeping its own stack and registers. Creating or switching processes is costly; threads are comparatively light, but their shared memory means synchronization is needed. In practice, the CPU scheduler often moves threads, not whole processes.
When grown-ups say it
- Process
- One independent car. Has its own memory space.
- Thread
- Hands working inside the same car. Shares code and the trunk (memory); keeps its own stack.
- Context Switch
- The time cost of switching to a different car. Much lighter for threads than for whole processes.
- Synchronization
- The rule for handing out the lift key. Especially important for threads sharing one trunk. → there's only one lift key
- Deadlock
- Frozen forever, each waiting on the other's key. Can happen between threads or between processes. → the garage frozen waiting on each other's keys
- Virtual Memory
- A fake map that makes the whole warehouse look like mine. Each process gets its own copy of this fake map. → the fake map that makes the whole warehouse yours
- CPU Scheduling
- The rule that sets the car order on the board. What actually lands on the board is usually a thread. → who gets the lift first
- The GPU's Many Hands
- A crew doing the same simple task all at once. Both split work among many hands, but a GPU specializes in running the same calculation at once. → the hundred-hand helper crew