A thread is the smallest unit of execution within a process. A process can contain many threads that share its memory (code, data, heap) but each have their own stack and registers. Threads make a program responsive and able to use multiple CPU cores.
Threads share, processes don't
Threads of the same process share the address space — so communication is cheap, but they can corrupt each other's data without care. Separate processes have isolated memory — safer, but heavier to create and to communicate between.
| Aspect | Process | Thread |
|---|---|---|
| Memory | own address space | shares the process's memory |
| Creation | heavy | light |
| Communication | IPC (slow) | shared memory (fast) |
| Crash impact | isolated | can crash the whole process |
| Context switch | expensive | cheaper |
⚡ The edge
- One line nails the comparison: processes are isolated, threads are shared. Threads are cheaper to create and switch, but a bug in one thread can bring down the whole process.
- Concurrency is dealing with many tasks by interleaving them (one core, time-sliced); parallelism is actually running them at the same instant (multiple cores).
Worked example
'What is the difference between a thread and a process?'
- State the unit: a process is an independent program in execution; a thread is a lighter unit of execution inside a process.
- Give the key difference: threads of a process share memory; processes have separate address spaces.
- Add the trade-off: threads are faster to create and communicate, but less isolated — one bad thread can crash the process.
Answer: A thread is a lightweight unit inside a process that shares the process's memory; processes are isolated.
Worked example
'Explain concurrency vs parallelism.'
- Concurrency is structuring a program to handle multiple tasks that make progress by interleaving — possible even on one core.
- Parallelism is literally executing multiple tasks simultaneously, which needs multiple cores.
- Analogy: one cook switching between dishes is concurrency; two cooks each on a dish is parallelism.
Answer: Concurrency = interleaving many tasks; parallelism = running them at the same instant on multiple cores.
⚠ Watch out
- Don't say threads have separate memory — they share the process's address space (only stack/registers are per-thread).
- Concurrency ≠ parallelism: you can have concurrency on a single core.
- Shared memory between threads is the source of race conditions — which is why synchronization exists.