Use cases - CPU-Intensive Tasks
What's the problem?
One thread = one core. If your task is heavy (e.g., calculating 1 million primes), the thread will use one CPU core only.
Single-threaded issue:
Even if you have 8 CPU cores, you're only using 1. Wasteful.
Multi-threaded solution:
Split the work into chunks, run each on a separate thread. Parallelism = much faster.
Example: Prime number calculator
- 1 million numbers → find primes.
- Split into 4 chunks.
- Use 4 threads → 4 CPU cores at once.
this can reduce total runtime because 4 cores are working simultaneously.