tech-notes-and-questions

Concurrency VS Parallelism

Concurrency is one CPU alternating between multiple tasks by context-switching, so there is progress in all of those tasks.

Parallelism is multiple CPUs working on multiple tasks; each core handles a different task independently at the same time.

Concurrency

Definition

Concurrency refers to the ability of a system to handle multiple tasks at the same time by allowing them to make progress. This doesn’t necessarily mean they are being executed simultaneously; rather, it means that tasks are overlapping in execution.

Key Characteristics

Concurrency

Example

In a web server handling multiple requests, the server can start processing one request while waiting for I/O operations (like database queries) to complete for another request.

Parallelism

Definition

Parallelism is a specific form of concurrency that involves executing multiple tasks simultaneously, typically on multiple processors or cores. It is concerned with the actual simultaneous execution of tasks.

Parallelism

Key Characteristics

Example

  1. A program that processes an image by splitting it into sections and processing each section on a separate core is an example of parallelism.
  2. Video rendering benefits from parallelism by processing multiple frames simultaneously across multiple cores.
  3. Machine learning can leverage parallelism by distributing the training across multiple CPUs.

Summary

Concurrency with Parallelism