Concurrency vs Parallelism
Concurrency and parallelism both sound like doing many things at once, but they are not the same thing. Concurrency means tasks take turns over the same span of time. One core can do it. Parallelism means tasks run at the very same instant, each on its own core. A program can be concurrent but not parallel, and the other way round.
Concurrency
Handling many tasks in the same stretch of time by taking turns.
Concurrency is a program dealing with many tasks over the same span of time. The tasks take turns. Each one moves on, even if only one runs at a time. While one task waits, say for a file or the network, another runs. The event loop and async code in JavaScript work this way on one thread. Running at the very same instant is a different idea, called parallelism.
Parallelism
Doing many tasks at once, each on its own core.
Parallelism is running several tasks at the very same instant on different CPU cores. A big job is split into parts, and each core works on one part. A laptop with 8 cores can, at best, finish such a job about 8 times faster. In practice the gain is smaller, because the parts must be split and joined again. Parallelism needs more than one core, while concurrency does not.
In one line
- Concurrency
- Handling many tasks in the same stretch of time by taking turns.
- Parallelism
- Doing many tasks at once, each on its own core.