• Keine Ergebnisse gefunden

DasMutual-Exclusion-Problem Prinzipien,Modelle&AlgorithmenderNebenl¨aufigenProgrammierung

N/A
N/A
Protected

Academic year: 2021

Aktie "DasMutual-Exclusion-Problem Prinzipien,Modelle&AlgorithmenderNebenl¨aufigenProgrammierung"

Copied!
134
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prinzipien, Modelle & Algorithmen der Nebenl¨aufigen Programmierung Wintersemester 2020/21

Das Mutual-Exclusion-Problem

Prof. Dr. David Sabel

LFE Theoretische Informatik

(2)

Ubersicht ¨

1 Einleitendes Beispiel: Too much milk

2 Formalisierung des Mutual-Exclusion-Problems

3 Algorithmen f¨ur 2 Prozesse mit atomarem Read & Write Dekkers Algorithmus

Petersons Algorithmus Kessels’ Algorithmus

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 2/35 Too much milk Formales Modell Atomic read/write

(3)

Einleitendes Beispiel: Too much milk

Alice und Bob teilen sich einen K¨ uhlschrank

Sie wollen, dass stets genug Milch im K¨ uhlschrank ist Weder zuviel noch zu wenig Milch.

Naive L¨osung

Wenn jemand sieht, dass keine Milch im K¨ uhlschrank ist, geht er Milch kaufen.

(4)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 4/35 Too much milk Formales Modell Atomic read/write

(5)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank

17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

(6)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 4/35 Too much milk Formales Modell Atomic read/write

(7)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

(8)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 4/35 Too much milk Formales Modell Atomic read/write

(9)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

(10)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 4/35 Too much milk Formales Modell Atomic read/write

(11)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

(12)

Naive L¨ osung funktioniert nicht

Alice Bob

17:00 kommt nach Hause

17:05 bemerkt: keine Milch im K¨ uhlschrank 17:10 geht zum Supermarkt

17:15 kommt nach Hause

17:20 bemerkt: keine Milch im K¨ uhlschrank

17:25 geht zum Supermarkt

17:30 kommt vom Supermarkt zur¨ uck, packt Milch in den K¨ uhlschrank

17:40 kommt vom Supermarkt zur¨ uck,

packt Milch in den K¨ uhlschrank

=⇒ Zuviel Milch im K¨uhlschrank

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 4/35 Too much milk Formales Modell Atomic read/write

(13)

Too much milk: Spezifikation

Alice und Bob vereinbaren,

Notizen am K¨uhlschrank

zu hinterlassen, die beide lesen k¨ onnen.

Dadurch soll sichergestellt werden, dass:

H¨ ochstens einer von beiden geht Milch kaufen, wenn keine Milch im K¨ uhlschrank ist.

Einer von beiden geht Milch kaufen, wenn keine Milch im K¨ uhlschrank ist.

Nicht erlaubt:

Nur Bob kauft Milch. Weil: Alice dann u.U. unendlich lange auf Milch wartet. (verletzt 2. Bedingung)

Annahme:

Alice und Bob k¨ onnen sich nicht sehen, d.h. sie kommunizieren nur ¨ uber die

Notizen

(14)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(15)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

(16)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(17)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

(18)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(19)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

(20)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(21)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

(22)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(23)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

(24)

1. L¨ osungsversuch

Wenn keine Notiz am K¨ uhlschrank und keine Milch im K¨ uhlschrank ist, dann schreibe Notiz an den K¨ uhlschrank, gehe Milch kaufen, stelle die Milch in den K¨ uhlschrank und entferne danach die Notiz am K¨ uhlschrank.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)ifkeine Notizthen (B1)ifkeine Notizthen (A2) ifkeine Milchthen (B2) ifkeine Milchthen (A3) schreibe Notiz; (B3) schreibe Notiz;

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz; (B5) entferne Notiz;

Notiz

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 6/35 Too much milk Formales Modell Atomic read/write

(25)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(26)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 7/35 Too much milk Formales Modell Atomic read/write

(27)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(28)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5)entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 7/35 Too much milk Formales Modell Atomic read/write

(29)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5)entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(30)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 7/35 Too much milk Formales Modell Atomic read/write

(31)

2. L¨ osungsversuch

Hinterlasse als erstes eine Notiz am K¨ uhlschrank, dann pr¨ ufe ob eine Notiz des anderen vorhanden ist. Nur wenn keine weitere Notiz vorhanden ist, pr¨ ufe ob Milch vorhanden ist und gehe Milch kaufen, wenn keine Milch vorhanden ist. Danach entferne die Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2) ifkeine Notiz von Alice then (A3) ifkeine Milchthen (B3) ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Keine Milch!

(32)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)schreibe Notiz “Alice”; (B1)schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(33)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1)schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

(34)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(35)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(36)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5)entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(37)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

(38)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(39)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(40)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5)entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(41)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1)schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

(42)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(43)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

(44)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5)entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(45)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

Alice

Bob

(46)

3. L¨ osungsversuch

Alice

Wie vorher: Schreibe Notiz, wenn keine Notiz von Bob, pr¨ufe ob Milch vorhanden und gehe Milch kaufen. Entferne Notiz.

Bob

Schreibe Notiz, warte bis keine Notiz von Alice am K¨uhlschrank h¨angt, dann pr¨ufe, ob Milch leer ist, gehe Milch kaufen, entferne eigene Notiz.

Als Prozesse:

Programm f¨ur Alice: Programm f¨ur Bob:

(A1) schreibe Notiz “Alice”; (B1) schreibe Notiz “Bob”;

(A2)ifkeine Notiz von Bobthen (B2)whileNotiz von Alicedo skip;

(A3) ifkeine Milchthen (B3)ifkeine Milchthen

(A4) kaufe Milch; (B4) kaufe Milch;

(A5) entferne Notiz “Alice”; (B5) entferne Notiz “Bob”;

L¨osung funktioniert nur, wenn die relative Geschwindigkeit passt. Sonst:

(A1),(B1),(B2),(A2),(A5),(A1),(B2)

| {z }

unendlich oft

ohne Milch zu kaufen

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 8/35 Too much milk Formales Modell Atomic read/write

(47)

Eine korrekte L¨ osung

Programm f¨ur Alice (A1) schreibe a1;

(A2)ifb2

(A3) thenschreibe a2;

(A4) elseentferne a2;

(A5)whileb1∧((a2∧b2)∨(¬a2∧ ¬b2)) (A6) do skip;

(A7)ifkeine Milch (A8) thenkaufe Milch;

(A9) entferne a1;

Programm f¨ur Bob (B1) schreibe b1;

(B2)if¬a2

(B3) thenschreibe b2;

(B4) elseentferne b2

(B5)whilea1∧((a2∧ ¬b2)∨(¬a2∧b2)) (B6) do skip;

(B7)ifkeine Milch (B8) thenkaufe Milch;

(B9) entferne b1;

a1 a2 b2 b1 pr¨ uft Milch

X

dc dc

×

Alice

×

dc dc

X

Bob

dc = don’t care

a1 a2 b2 b1 pr¨ uft Milch

X × X X

Alice

X X × X

Alice

X X X X

Bob

X × × X

Bob

(48)

Eine korrekte L¨ osung

Programm f¨ur Alice (A1) schreibe a1;

(A2)ifb2

(A3) thenschreibe a2;

(A4) elseentferne a2;

(A5)whileb1∧((a2∧b2)∨(¬a2∧ ¬b2)) (A6) do skip;

(A7)ifkeine Milch (A8) thenkaufe Milch;

(A9) entferne a1;

Programm f¨ur Bob (B1) schreibe b1;

(B2)if¬a2

(B3) thenschreibe b2;

(B4) elseentferne b2

(B5)whilea1∧((a2∧ ¬b2)∨(¬a2∧b2)) (B6) do skip;

(B7)ifkeine Milch (B8) thenkaufe Milch;

(B9) entferne b1;

a1 a2 b2 b1 pr¨ uft Milch

X

dc dc

×

Alice

×

dc dc

X

Bob

dc = don’t care

a1 a2 b2 b1 pr¨ uft Milch

X × X X

Alice

X X × X

Alice

X X X X

Bob

X × × X

Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 9/35 Too much milk Formales Modell Atomic read/write

(49)

Eine korrekte L¨ osung

Programm f¨ur Alice (A1) schreibe a1;

(A2)ifb2

(A3) thenschreibe a2;

(A4) elseentferne a2;

(A5)whileb1∧((a2∧b2)∨(¬a2∧ ¬b2)) (A6) do skip;

(A7)ifkeine Milch (A8) thenkaufe Milch;

(A9) entferne a1;

Programm f¨ur Bob (B1) schreibe b1;

(B2)if¬a2

(B3) thenschreibe b2;

(B4) elseentferne b2

(B5)whilea1∧((a2∧ ¬b2)∨(¬a2∧b2)) (B6) do skip;

(B7)ifkeine Milch (B8) thenkaufe Milch;

(B9) entferne b1;

a1 a2 b2 b1 pr¨ uft Milch

X

dc dc

×

Alice

×

dc dc

X

Bob

dc = don’t care

a1 a2 b2 b1 pr¨ uft Milch

X × X X

Alice

X X × X

Alice

X X X X

Bob

X × × X

Bob

bedeutet “... will an den K¨uhlschrank”

(50)

Eine korrekte L¨ osung

Programm f¨ur Alice (A1) schreibe a1;

(A2)ifb2

(A3) thenschreibe a2;

(A4) elseentferne a2;

(A5)whileb1∧((a2∧b2)∨(¬a2∧ ¬b2)) (A6) do skip;

(A7)ifkeine Milch (A8) thenkaufe Milch;

(A9) entferne a1;

Programm f¨ur Bob (B1) schreibe b1;

(B2)if¬a2

(B3) thenschreibe b2;

(B4) elseentferne b2

(B5)whilea1∧((a2∧ ¬b2)∨(¬a2∧b2)) (B6) do skip;

(B7)ifkeine Milch (B8) thenkaufe Milch;

(B9) entferne b1;

a1 a2 b2 b1 pr¨ uft Milch

X

dc dc

×

Alice

×

dc dc

X

Bob

dc = don’t care

a1 a2 b2 b1 pr¨ uft Milch

X × X X

Alice

X X × X

Alice

X X X X

Bob

X × × X

Bob

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 9/35 Too much milk Formales Modell Atomic read/write

versucht Vorrang an Bob zu geben

(51)

Eine korrekte L¨ osung

Programm f¨ur Alice (A1) schreibe a1;

(A2)ifb2

(A3) thenschreibe a2;

(A4) elseentferne a2;

(A5)whileb1∧((a2∧b2)∨(¬a2∧ ¬b2)) (A6) do skip;

(A7)ifkeine Milch (A8) thenkaufe Milch;

(A9) entferne a1;

Programm f¨ur Bob (B1) schreibe b1;

(B2)if¬a2

(B3) thenschreibe b2;

(B4) elseentferne b2

(B5)whilea1∧((a2∧ ¬b2)∨(¬a2∧b2)) (B6) do skip;

(B7)ifkeine Milch (B8) thenkaufe Milch;

(B9) entferne b1;

a1 a2 b2 b1 pr¨ uft Milch

X

dc dc

×

Alice

×

dc dc

X

Bob

dc = don’t care

a1 a2 b2 b1 pr¨ uft Milch

X × X X

Alice

X X × X

Alice

X X X X

Bob

X × × X

Bob

versucht Vorrang an Alice zu geben

(52)

Im Folgenden:

Mutual-Exclusion-Problem:

Formalisierung

Definition des Problems und einer L¨ osung Annahmen ¨ uber das Modell Deadlock- bzw. Starvation-Freiheit

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 10/35 Too much milk Formales Modell Atomic read/write

(53)

Das Mutual-Exclusion-Problem

Mutual-Exclusion-Problem informell:

Garantie, dass der

exklusive Zugriff

auf eine gemeinsam genutzte Ressource sichergestellt wird

Zugriffscode wird als

kritischer Abschnitt

bezeichnet.

Race Condition: Situationen in denen mehrere Prozesse auf eine gemeinsame

Ressource zugreifen und der Wert der Ressource h¨ angt von

Ausf¨ uhrungsreihenfolge ab.

Ziel des Mutual-Exclusion-Problems:

Vermeide Race Conditions

(54)

Das Mutual-Exclusion-Problem, formales Modell

Code-Struktur jedes Prozesses

loop forever

restlicher Code Initialisierungscode Kritischer Abschnitt Abschlusscode

end loop

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 12/35 Too much milk Formales Modell Atomic read/write

(55)

Das Mutual-Exclusion-Problem, formales Modell (2)

Annahmen

Im restlichen Code kann ein Prozess keinen Einfluss auf andere Prozesse nehmen.

Ansonsten ist dort alles erlaubt (Endlosschleifen usw.)

Ressourcen (Programmvariablen), die im Initialisierungscode oder Abschlusscode benutzt werden, werden durch den Code im Kritischen Abschnitt und den restlichen Code nicht ver¨ andert.

loop forever restlicher Code Initialisierungscode Kritischer Abschnitt Abschlusscode end loop

(56)

Das Mutual-Exclusion-Problem, formales Modell (3)

Annahmen (Fortsetzung)

Keine Fehler bei Ausf¨ uhrung des Initialisierungscodes, des Codes im kritischen Abschnitt und im Abschlusscode

Code im kritschen Abschnitt und im Abschlusscode:

Nur endlich viele Ausf¨ uhrungsschritte (keine Schleifen!).

Impliziert (wegen Fairness): Prozess verl¨ asst nach Betreten des kritischen Abschnitt diesen und f¨ uhrt Abschlusscode durch.

loop forever restlicher Code Initialisierungscode Kritischer Abschnitt Abschlusscode end loop

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 14/35 Too much milk Formales Modell Atomic read/write

(57)

Korrektheitskriterien

L¨osung des Mutual-Exclusion-Problems

F¨ ulle Initialisierungs- und Abschlusscode, so dass die folgenden Anforderungen erf¨ ullt sind:

Wechselseitiger Ausschluss: Es sind niemals zwei oder mehr Prozesse zugleich in

ihrem kritischen Abschnitt.

Deadlock-Freiheit: Wenn ein Prozess

seinen kritischen Abschnitt betreten m¨ ochte,

dann betritt

irgendein

Prozess schließlich den kritischen Abschnitt.

(58)

Korrektheitskriterien (2)

St¨ arkere Forderung gegen¨ uber Deadlock-Freiheit:

Starvation-Freiheit

Starvation = Verhungern

Starvation-Freiheit: Wennein Prozess

seinen kritischen Abschnitt betreten m¨ ochte, dann muss

er

ihn nach endlich vielen Berechnungsschritten betreten.

Ein Starvation-freier Algorithmus ist auch Deadlock-frei.

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 16/35 Too much milk Formales Modell Atomic read/write

(59)

Formale Beweistechniken

Wechselseitiger Ausschluss ist eine sog.

Sicherheitseigenschaft

(Safety Property), eine Eigenschaft die

immer

erf¨ ullt sein muss.

Deadlock- bzw. Starvation-Freiheit sind sog.

Lebendigkeitseigenschaften

(Liveness Property), Eigenschaften die irgendwann erf¨ ullt sein m¨ ussen.

Mittels Temporallogik l¨ asst sich formal nachweisen, dass diese Eigenschaften erf¨ ullt sind.

Z.B. kann Model-Checking f¨ ur den Beweis verwendet werden

Wir machen die Beweise direkt (eher informell).

(60)

Wir betrachten:

L¨ osungen zum Mutual-Exclusion-Problem bei 2 Prozessen

und atomarem Lesen und Schreiben

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 18/35 Too much milk Formales Modell Atomic read/write

(61)

Algorithmen f¨ ur 2 Prozesse mit atomarem Read+Write

Im Folgenden:

Einige Algorithmen zum Mutual-Exclusion-Problem Nebenl¨ aufiges Programm mit genau

zwei

Prozessen Annahmen:

Als atomare Speicheroperationen des gemeinsamen Speichers nur

Lesen

und

Schreiben

Z.B. verboten swap(X,Y), X := Y , etc. f¨ ur gemeinsame Variablen Abk¨ urzung:

await Bedingung;

anstelle von

while ¬Bedingung do skip;

(62)

Dekkers Algorithmus

Historisch die erste korrekte L¨ osung

Theodorus Jozef Dekker = Niederl¨ andischer Mathematiker Erw¨ ahnung des Dekker-Algorithmus: Dijkstra 1965

Nicht ganz einfache L¨ osung

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 20/35 Too much milk Formales Modell Atomic read/write

(63)

Algorithmus von Dekker

Initial:wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt

(64)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt wantp=False, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(65)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt

(66)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt wantp=True, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(67)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt

(68)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt wantp=True, wantq =False , turn =2

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(69)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: NurP will in den kritischen Abschnitt

(70)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=False, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(71)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(72)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(73)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(74)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(75)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(76)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =True , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(77)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(78)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =True , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(79)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(80)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(81)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(82)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =False , turn =2

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(83)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(84)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=True, wantq =False , turn =2

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(85)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(86)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=False, wantq =True , turn =2

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(87)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(88)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=False, wantq =True , turn =2

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

(89)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt

(90)

Algorithmus von Dekker

Initial: wantp = False, wantq = False, turn =1

ProzessP: ProzessQ:

loop forever

(P1) restlicher Code (P2) wantp := True;

(P3) whilewantqdo (P4) ifturn=2then (P5) wantp := False;

(P6) awaitturn=1;

(P7) wantp := True;

(P8) Kritischer Abschnitt (P9) turn := 2;

(P10) wantp := False;

end loop

loop forever

(Q1) restlicher Code (Q2) wantq := True;

(Q3) whilewantpdo (Q4) ifturn=1then (Q5) wantq := False (Q6) awaitturn=2 (Q7) wantq := True;

(Q8) Kritischer Abschnitt (Q9) turn := 1;

(Q10) wantq :=False;

end loop

Durchlauf: P zuerst im kritischen Abschnitt wantp=False, wantq =False , turn =1

TCS | 03 Das Mutual-Exclusion-Problem | WS 2020/21 21/35 Too much milk Formales Modell Atomic read/write

Referenzen

ÄHNLICHE DOKUMENTE

Es gibt keinen (Deadlock-freien) Mutual-Exclusion-Algorithmus f¨ ur 2 (oder auch n) Prozesse, der eine obere Schranke hat f¨ ur die Anzahl an Speicherzugriffen (des

Ein gemeinsames Speicherregister mit Werten 0 und 1 alternative test-and-set -Operationen setzt Register auf 1 reset -Operation: atomares Schreiben einer 0 in das

bereit/ready: Prozess will Schritte ausf¨ uhren, darf aber nicht mindestens ein Prozess l¨ auft immer (z.B. Leerlaufprozess) Scheduler f¨ uhrt Context-Switch aus:.. Bereite

signalC(cond) kann effektlos sein: Entwe- der Prozess in cond wird entblockiert, oder effektlos, wenn cond leer ist. TCS | 09 Monitore | WS 2020/21 17/53 Monitore

Ein Kanal verbindet einen sendenden Prozess mit einem empfangenden Prozess Oft erlaubt: ein Kanal verbindet mehrere sendende und empfangende Prozesse Kan¨ ale sind typisiert:

Im Tuple Space muss ein “Matching Tuple“ vorhanden sein Matching Tuple = gleiche L¨ ange, gleiche Typen, gleiche Werte Falls kein passendes Tuple vorhanden:.. Prozess blockiert, bis

2 Halten und Warten (Hold and Wait): Ein Prozess kann eine Ressource anfordern (auf eine Ressource warten), w¨ ahrend er eine andere Ressource bereits belegt hat.. 3

Annahme: getZahl w¨ are eine “Funktion”, die eine Zahl von der Standardeingabe liest Referentielle Transparenz ist verletzt, da getZahl je nach Ablauf unterschiedliche Werte