1 Trains Boliviens et Péruviens

Transcription

1 Trains Boliviens et Péruviens
Université de Nice-Sophia Antipolis
Licence S & T
Lundi 11 février 2008
Durée: 2h00
L3I6 : Systèmes et Réseaux TD 1
Françoise Baude ([email protected])
1
Trains Boliviens et Péruviens
Dans le texte en anglais qui suit, pour chaque Explain., donnez un algorithme
modélisant la situation, puis proposez une explication.
High in the Andes mountains, there are two circular railroad lines. As shown in the
diagram, one line is in Peru, the other in Bolivia. They share a section of track, where
the lines cross a mountain pass that lies on the international border.
Unfortunately, the Peruvian and Bolivian trains occasionaly collide when simultaneously entering the critical section of track (the mountain pass). The trouble is, alas,
1
that the drivers of the two trains are blind and deaf, so they can neither see nor hear
each other.
The two drivers agreed on the following method of preventing collisions. They set up
a large bowl at the entrance to the pass. Before entering the pass, a driver must stop his
train, walk over to the bowl, and reach into it to see if it contains a rock. If the bowl
is empty, the driver nds a rock and drops it in the bowl, indicating that his train is
entering the pass ; once his train has cleared the pass, he must walk back to the bowl and
remove his rock, indicating that the pass is no longer being used. Finally, he walks back
to the train and continues down the line. If a driver arriving at the pass nds a rock in
the bowl, he leaves the rock there ; he repeatedly takes a siesta and rechecks the bowl until
he nds it empty. Then he drops a rock in the bowl and drives his train into the pass.
A smart aleck1 college graduate from the University at La Paz (Bolivia) claimed that
subversive train schedules made up by Peruvian ocials could block the Bolivian trains
forever. (Explain). The Bolivian driver just laughed and said that could not be true
because it never happened. (Explain). Unfortunately, one day the two trains crashed.
(Explain).
Following the crash, our college graduate was called in as a consultant to ensure that
no more crashes would occur. He explained that the bowl was being used the wrong way.
The Bolivian driver must wait at the entry until the bowl is empty, drive through the
pass, and walk back to put a rock in the bowl. The Peruvian driver must wait at the entry
until the bowl contains a rock, drive through the pass and walk back to remove the rock
from the bowl. Sure enough, his method prevented crashes. Prior to the arrangement,
the Peruvian train ran twice a day and the Bolivian train ran once a day. The Peruvian
were very unhappy with the new arrangement. (Why ?)
Our college graduate was called in again and was told to prevent crashes while avoiding the problem of his previous method. He suggested that two bowls be used, one for
each driver. When a driver reaches the entry, he rst drops a rock in his bowl, then
checks the other bowl to see if it is empty. If so, he drives his train through the pass,
stops it and walks back to remove his rock. But if he nds a rock in the other bowl he
goes back to his bowl and removes his rock. Then he takes a siesta, again drops a rock
in his bowl, and re-checks the other bowl and so on, until he nds the other bowl empty.
This method worked ne until late in May, when the two trains were simultaneously
blocked at the entry for many siestas (Explain).
To solve this problem, a Dutch mathematician named Dekker was brought in. What
did he recommand2 ? Another Dutchman named Dijkstra said there was a better wayn
using a single bowl as a semaphore. What did he call the bowl ?
1
2
Smart aleck (slang) : A person regarded as obnoxiously self-assertive.
Voir l'algorithme donné plus loin.
2
2
Algorithme de Dekker
C'est une solution logicielle qui utilise une variable tour et deux booléens initialisés
à faux : p1_veut_entrer et p2_veut_entrer.
Déclarations communes :
var p1_veut_entrer : boolean ;
p2_veut_entrer : boolean ;
tour : 1..2 ;
L'algorithme du Processus P1 est le suivant :
intialisations:
p1_veut_entrer := false ;
p2_veut_entrer := false ;
tour := 1 ;
/* ou 2 */
repeat
p1_veut_entrer := true ;
while (p2_veut_entrer) do
if (tour = 2) then
begin
p1_veut_entrer := false ;
while (tour = 2) do ;
/* attendre */
p1_veut_entrer := true ;
end ;
Section Critique
tour := 2 ;
p1_veut_entrer := false ;
Section Restante
until false ;
3
1. La propriété d'exclusion mutuelle est-elle préservée ?
2. La propriété de non-blocage est-elle préservée ?
3. Hypothèses : P2 est en attente dans la boucle while (tour = 1) do ; et P1 est
en SC. La propriété suivante est-elle vériée : si P1 conserve l'unité centrale,
il peut exécuter sa SC autant de fois qu'il le désire . En revanche, lorsque P1 a
exécuté sa section de sortie, P2 peut entrer en SC dès que l'UC lui est accordée.
4. Vérier la propriété de progression : un processus en Section Restante ne peut pas
empêcher un autre processus d'entrer en SC.
5. La propriété d'attente bornée est réalisée si l'on adopte la convention suivante :
lorsqu'un Processus Pi est dans sa section d'entrée avec le booléen pi_veut_entrer
à faux, il n'est provisoirement plus en attente de sa section critique.
6. Comparer avec la solution de Peterson :
repeat
p1_veut_entrer := true ;
tour := 2;
while (p2_veut_entrer et tour = 2) do ;
Section Critique
p1_veut_entrer := false ;
Section Restante
until false ;
3
/* attente */
Utilisation de sémaphore pour l'exclusion mutuelle
1. L'outil sémaphore est un outil puissant, qui peut entre autre permettre de résoudre
l'exclusion mutuelle. Rappeler de quelle manière on peut s'en servir. Discuter
et comparer avec l'utilisation d'une solution dite sans arbitrage comme celle de
Peterson ou de Dekker, selon les critères tels : connaissance a priori des processus
en concurrence, temps d'occupation du CPU.
2. Pour que l'outil sémaphore puisse servir à résoudre le problème de l'exclusion
mutuelle, il faut que les procédures P et V soient elles-même exécutées en exclusion
mutuelle. (Ce qui revient à considérer que la valeur du sémaphore est elle-même
une ressource dont l'usage doit être contrôlé).
Identier précisément quel est le problème rencontré si plusieurs exécutions de la
procédure P peuvent s'entrelacer ?
Identier précisément quel est le problème rencontré si une exécution de V peut
s'entrelacer avec une exécution de P ?
4

Documents pareils