Professional Documents
Culture Documents
CONCURRENT PROGRAMMING.
very huge...
If there are n processes and each one has m atomic
instructions, the total number of possible interleavings is
( n m)!
n
( m! )
Nondeterminism and the number of
interleavings
If there are n processes and each one has m atomic
instructions, the total number of possible interleavings is
( n m)!
( m! ) n
Processes
2 3 4 5
2 6 90 2520 113400
instructions
Alice and Bernard have been married for a time. Bernard is not only a peculiar guy but
also has a deep sense of chivalry. Bernard NEVER starts eating his dinner before Alice has
started eating hers (this peculiar rule does not apply to breakfast or lunch, only to dinner).
One day, Bernard has to go to work to another city...
This solution is
correct but…
COULD
ANYTHING GO
WRONG?
YES...
Alice could STARVE (kill of hunger) Bernard!!!
Charles and Dora work in a nuclear power plant. They spend each working day in
two different rooms monitoring the lights and dials that show the state of the plant.
If anything goes wrong any of them can set off an alarm. Charles and Dora are a
“redundant system”: they do exactly the same in order to guarantee a higher
degree of reliability.
Charles and Dora can leave their room to have breakfast provided they do not
leave the plant unattended. Thus, at any given time only one can be having
breakfast.
In each room there is a red-or-green light. When it’s red it means it is not safe to
leave the room because the other is out. If it’s green then it is safe to leave. Also, in
each room there’s a switch that sets the light in the other room.
This is a mutual exclusion problem that takes place in
a shared-memory environment.
Breakfast is a “CRITICAL SECTION” only one of the
actors (processes) can be in it at any given time
Charles, Dora and the power plant problem
(a mutual exclusion problem)