placeholderConcurrency & Parallelism Etc.

Concurrency & Parallelism Etc.

Notes on concurrency, parallelism, CPU cores, hardware threads, processes, and threads in operating systems.
ItemConceptRelated Concepts
Number of CPUsThe number of CPUs installed in a computerMultiprocessor system
Number of CPU cores
(physical cores)
A CPU can contain multiple dies, and each die can contain multiple cores. The number of cores is the CPU core countWafer, die,
core, CPU
Number of CPU threads
(logical cores)
Intel’s Hyper-Threading technology allows one core to execute multiple threads at the same time.
8 cores and 16 threads means one core can run two threads, for a total of 16 threads
Hyper-Threading

Understanding the relationship between wafer, die, and CPU - Juejin
A Simple Understanding of CPU physical count, cores, threads, processes, threads, coroutines, concurrency, and parallelism - Zhihu

  • Process: the basic unit by which the operating system allocates and manages resources. The OS can allocate resources such as CPU time and memory according to each process’s needs and priority.
  • Thread: the basic unit of CPU scheduling and resource allocation. In a multithreaded OS, a thread is the basic unit that runs independently, so it is also the basic unit scheduled and allocated independently.

Concurrency & Parallelism

DefinitionDiagram
ParallelismMultiple computational tasks execute at the same physical moment
image
image

ConcurrencyMultiple computational tasks make progress within the same time period
image
image

The diagram below shows how single-core and multi-core CPUs support concurrency and parallelism. Parallelism requires hardware support; a single-core CPU can only provide concurrency.

concurrency_vs_parallelism

The two are not opposites. For I/O-intensive tasks, when a process or thread is blocked on I/O, the CPU can be assigned to a ready process or thread to avoid sitting idle. Multi-core CPUs also need this strategy to improve CPU utilization.