Skip to main content

Concurrency

Main Source:

  • Book 2 chapter 12

A program is concurrent when it contains more than one active execution context, whether both is run together or interleaved. By execution context, it means the state associated with the execution of a particular task. It includes information such as the values of registers, stack pointer, call stack, etc.

The approach for concurrency:

  • Multithreading: The use of thread for a single execution context, and multiple of them to achieve parallel execution.
  • Multiprocessing: A process is instance of running program that run in separate memory spaces. CPU with multiple core (multiprocessor) can be utilized to run multiple processes in parallel multiprocessing.
  • Coroutine: Coroutine is an approach to interleave execution of different tasks. It still relies on thread, but the less number of thread is needed to achieve concurrency (although not parallel).