Skip to content
BENIBIX Learn

Concurrency

Development⚙️ Compilers & RuntimesConcurrency

Also known as Concurrent Programming, Concurrent

Handling many tasks in the same stretch of time by taking turns.

Think of it like

Think of it like one cook making soup and toast. They stir, then butter, then stir again.

Example

Lucy's Node.js server handles 1,000 visitors on one thread. While one request waits for the database, it starts on the next.

Why it matters

Most programs spend their time waiting. With concurrency they can do useful work while they wait.

Definition

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.

Common mistake

Thinking concurrent code runs on many CPU cores at once. It may run on just one, taking turns very fast.

Key takeaways

  1. 1
    Take turns. Each task moves forward.
  2. 2
    Use the waits. Run another task meanwhile.
  3. 3
    Not always parallel. One core can do it.

Compare