master-degree-notes/Concurrent Systems/notes/Lezione1.md

2.9 KiB
Raw Blame History

A sequential algorithm is the formal description of the behavior of an abstract state machine.

A program is a sequential algorithm written in a programming language.

A process is a program executed on a concrete machine, characterized by its state (values of the registers). If the process follows one single control flow (i.e. one program counter) then it is a sequential process, or thread.

A set of sequential state machines that run simultaneously and interact through shared memory through a shared medium is called concurrency. In a concurrent system there must be something shared.

Advantages of concurrent systems:
  • efficiency: run in parallel different stuff
  • simplification of the logic by dividing the task in simpler tasks, running them in different processes and combining the results together.

Features of a concurrent system

We can assume many features:

  • Reliable vs Unreliable
  • Synchronous vs Asynchronous
  • Shared memory vs Channel-based communication

Reliable system: every process correctly executes its program

Asynchronous: no timing assumption (every process has its own clock, which are independent one from the other)

Shared medium: A way is through a shared memory area, another way is through message passing. For this part of the course we assume that every process has a local memory but can access a shared part of the memory. We will assume that memory is split into registers (will see later).

For now, we will assume that processes won't fail. We also assume that we have one processor per process. But actually the processor can be a shared resource (more processes than processors).

Synchronization: cooperation vs competition

Definition of synchronization: the behavior of one process depends on the behavior of others.

This requires two fundamentals interactions:

  • Cooperation
  • Competition

Cooperation

Different processes work to let all of them succeed in their task.

  1. Rendezvous: every involved process has a control point that can be passed only when all processes are at their control point: the set of all control points is called barrier.
  2. Producer-consumer: two kind of processes, one that produces data and one that consumes them
    • only produced data can be consumed
    • every datum can be consumed at most once

Competition

Different processes aim at executing some action, but only one of them succeeds. Usually, this is related to the access of the same shared resource.

Example: two processes want to withdraw from a bank account.

function withdraw() {
	x := account.read();
	if x  1M {
		account.write(x  1M);
	}
}

While read() and write() may be considered as atomic, their sequential composition is not.

!Pasted image 20250303090135.png

Mutual Exclusion (MUTEX)

Ensure that some parts of the code are executed as atomic. This is needed in competition but also in cooperation.