Concurrency #
Core #
A core is a basic processing unit.
A Central Processing Unit (CPU) contains one or several cores (e.g. 4 or 8).
A Graphical Processing Unit (GPU) can contain thousands of cores.
Parallelism vs concurrency #
Terminology. We call time span of a (computational) tasks the time interval comprised between the task’s start and completion.
The time spans of two tasks may overlap.
Example. While downloading a video, Alice may use git to commit changes to her repository. These two tasks overlap.
Definitions. Two overlapping tasks can be executed either:
- on different cores: this is called parallelism, or
- on the same core, in an interleaved fashion: this is called concurrency.
Example. Consider a core that executes (sequentially) a task $t_1$ that repeatedly reads data from a database (stored on a hard drive). The core is likely to remain unused while data is being fetched from the hard drive. Instead, while $t_1$ is fetching data, the same core could be used to perform computations for a task $t_2$.
Context switch #
Definition. A context switch is the operation that consists in storing the system’s state for a running task (so that it can be paused and resumed later on), and restoring a different, previously saved state.