First let's understand some of the most confusing terms.
1. Multitasking
✅ Definition:
The ability of an operating system to run multiple programs (processes) at the same time by rapidly switching between them.
💡 Example:
- You are writing a Word document while listening to music and downloading a file — all at once.
- The OS switches between these apps so quickly it feels like they are running simultaneously.
🔧 Types:
- Preemptive Multitasking: The OS forcibly switches between tasks (used in modern OS).
- Cooperative Multitasking: Each task voluntarily gives up control (older systems).
2. Multithreading
✅ Definition:
The ability of a single process to be split into multiple threads that can run concurrently.
💡 Example:
- A browser (process) has:
- one thread rendering the page,
- another downloading data,
- and another handling user input — all at once.
🔍 Threads share:
- Code, data, heap (same memory)
- But each thread has its own stack and registers.
3. Concurrency
✅ Definition:
The ability to handle multiple tasks by interleaving their execution — switching between them efficiently, possibly on a single core.
💡 Example:
- A single-core CPU running multiple tasks by pausing one and starting another rapidly — it looks like they’re happening at the same time, but they aren’t.
🔧 Tools:
async/await
, coroutines, cooperative multitasking, event loops.
4. Parallelism
✅ Definition:
The ability to execute multiple tasks at the exact same time using multiple CPU cores or processors.
💡 Example:
- On a quad-core CPU, 4 threads can literally run in parallel, each on its own core.