Programming6 min read10 interview questions

Concurrency or parallelism

Doing many things at once versus doing things at the same moment.

In one sentenceConcurrency is managing several tasks by switching between them. Parallelism is truly running tasks at the same time on different processors.

Think of it like thisOne cook juggling three dishes is concurrency. Three cooks each making one dish is parallelism.

The big picture

Tap any step to see where to use it, how to use it and an example result.

Concurrency helps with waiting

Most programs spend a lot of time waiting for the network or disk. While one task waits, another can run. Async code and threads on a single core give this benefit.

Parallelism helps with heavy work

Calculations that keep a processor busy, such as resizing thousands of images, finish faster when split across several cores or machines.

The hazards

When tasks share data, they can overwrite each other's changes (a race condition) or wait for each other forever (a deadlock). Prefer passing messages or using locks and safe data structures, and keep shared data small.

Common mistakes

  • Using threads for work that needs more processing power in a language that limits it, without checking how.
  • Sharing changing data between tasks without protection.
  • Adding concurrency before measuring whether the program is actually waiting.

Quick recap

  • Concurrency is switching, parallelism is simultaneous
  • Waiting work suits concurrency
  • Heavy calculation suits parallelism
  • Shared data causes races and deadlocks

Try it yourself

Write a script that downloads ten web pages one after another, then with async or threads. Compare the times.

Top 10 interview questions

Ordered from basic to advanced. Try answering out loud first, then open the answer.

  1. What is concurrency?Basic

    Dealing with several tasks at once by switching between them, so progress is made on all of them even on a single worker.

  2. What is parallelism?Basic

    Actually running several tasks at the same moment, on different CPU cores or machines.

  3. How do concurrency and parallelism differ?Basic

    Concurrency is about structure: managing many things at once. Parallelism is about execution: doing many things at the same time. You can have either without the other.

  4. What is a thread, and what is a process?Basic

    A process is a running program with its own memory. Threads are lighter paths of execution inside a process that share its memory.

  5. What is a race condition?Intermediate

    A bug where the result depends on the unpredictable timing of tasks that share data, for example two threads updating the same counter at once and losing an update.

  6. What is a deadlock?Intermediate

    Two or more tasks each wait for something the other holds, so none can continue. Avoid it by taking locks in a consistent order, using timeouts and holding locks briefly.

  7. What is a lock (mutex) and what is the downside?Intermediate

    It lets only one task at a time use a shared resource. The downside is waiting, slower code and the risk of deadlock if used carelessly.

  8. What is the difference between CPU-bound and I/O-bound work?Intermediate

    CPU-bound work is limited by computation, so parallelism helps. I/O-bound work waits for networks or disks, so concurrency such as async code helps most.

  9. How does async/await work, and how is it different from threads?Advanced

    Async code runs on one thread and pauses at await points while waiting, letting other tasks run. It handles many waiting tasks cheaply, but a long calculation blocks everything.

  10. What are ways to avoid shared-state bugs?Advanced

    Prefer immutable data, pass messages instead of sharing memory, use queues or actors, use atomic operations or thread-safe structures, and keep shared state small and well guarded.

Back to Learn Hub

Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.