Threads vs Processes
A process is the fundamental unit that owns memory in an operating system. When a program starts, the OS sets up everything it needs:
This entire memory layout belongs to the process, not to any thread inside it.
Threads Live Inside a Process
A thread is not a separate program with its own memory. Instead, a thread represents an execution path running within the memory of its parent process.
You can think of a process as a house, and threads as people in different rooms:
But they all share:
So if one thread rearranges furniture (modifies memory), every other thread sees it instantly.
Memory Sharing Is Built Into Thread Architecture
When a process creates additional threads, the OS does not allocate new memory spaces. Instead:
This means:
A pointer created in one thread can be used in another without special handling.
This makes multi‑threading very fast for sharing data — there is no copy and no need for inter‑process communication (IPC).
What Memory Is Private to Each Thread?
Only three components are unique for every thread:
1. Its own stack
Used for:
Each thread gets its own stack region inside the process.
2. Its CPU registers
These store things like:
Recommended by LinkedIn
3. Its scheduling metadata
The OS keeps book‑keeping info about each thread:
Every other part of memory is shared across the process.
The Tradeoff: Speed vs Safety
Because threads share so much, thread‑to‑thread communication is extremely fast:
But the drawback is correctness.
❌ If two threads write to the same variable at the same time:
This leads to race conditions.
To prevent this, threads must use:
Without synchronization, shared memory becomes a source of unpredictable bugs.
Final Summary
Threads are fast because they share memory. But that same shared memory means:
In contrast, processes have:
So:
Threads trade isolation for raw execution efficiency. Processes trade efficiency for safety and separation.