Card 1 of 10 · Processes & threads
Process vs thread: what is the difference?
Say this first
A process is a running program with its own memory. Threads live inside a process and share its memory.
Picture it
Process
- • Own address space
- • Heavy to create and switch
- • Crash stays isolated
- • Talk via IPC (pipes, sockets)
Thread
- • Shares code, heap and globals
- • Light to create and switch
- • A bug can bring down the whole process
- • Own stack and registers
Try it
Two threads of one process both change the same global variable. What can go wrong?
Common trap
Saying threads have separate memory. They share the heap; only the stack is private.
Say it like this
A process has its own memory space, while threads share their process's memory, which makes them cheaper but needs synchronisation.