parallelism:deadlocks:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
parallelism:deadlocks:start [2025/03/20 15:38] – [Aufgabe 1: Das Philosophenproblem] Martin Pabst | parallelism:deadlocks:start [2025/04/08 10:54] (aktuell) – [Aufgabe 1: Das Philosophenproblem] Martin Pabst | ||
---|---|---|---|
Zeile 48: | Zeile 48: | ||
<WRAP center round todo 80%> | <WRAP center round todo 80%> | ||
* a) Erläutern Sie, inwiefern die Coffman-Bedingungen erfüllt sind. | * a) Erläutern Sie, inwiefern die Coffman-Bedingungen erfüllt sind. | ||
- | * b) Starten Sie das untenstehende Programm und untersuchen Sie, ob es zu einer Verklemmung kommt. Welche Rolle spielen die sleep-Anweisungen? | + | * b) Starten Sie das untenstehende Programm und untersuchen Sie, ob es zu einer Verklemmung kommt. Welche Rolle spielen die '' |
* c) Ändern Sie das Programm so ab, dass die Bedingung " | * c) Ändern Sie das Programm so ab, dass die Bedingung " | ||
- | * d) Ändern Sie das Programm so ab, dass | + | * d) Ändern Sie das Programm so ab, dass eine andere der Coffman-Bedingungen nicht mehr zutrifft. Erläutern Sie Ihr Vorgehen. |
</ | </ | ||
+ | < | ||
+ | <div class=" | ||
+ | |||
+ | <script type=" | ||
+ | new Main().setup(); | ||
+ | |||
+ | class Main { | ||
+ | |||
+ | int[] colors = { 0xff0000, 0x00ff00, 0x0000ff, 0x9614d3, 0xf5e400 }; | ||
+ | |||
+ | void setup() { | ||
+ | Fork[] forks = new Fork[5]; | ||
+ | for (int i = 0; i < 5; i++) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | for (int i = 0; i < 5; i++) { | ||
+ | new Philosopher(i, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | class Philosopher extends Thread { | ||
+ | |||
+ | int color; | ||
+ | Fork forkLeft; | ||
+ | Fork forkRight; | ||
+ | |||
+ | | ||
+ | Circle circle = new Circle(600, 300, 50); | ||
+ | circle.rotate(360 / 5.0 * number, 400, 300); | ||
+ | circle.setFillColor(color); | ||
+ | this.color = color; | ||
+ | this.forkLeft = forkLeft; | ||
+ | this.forkRight = forkRight; | ||
+ | } | ||
+ | |||
+ | | ||
+ | while (true) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | class Fork extends Line { | ||
+ | |||
+ | | ||
+ | int color = gray; | ||
+ | |||
+ | | ||
+ | super(500, 300, 580, 300); | ||
+ | setBorderColor(color); | ||
+ | rotate(360 / 10.0 + 360 / 5.0 * number, 400, 300); | ||
+ | } | ||
+ | |||
+ | | ||
+ | if(color != gray) { | ||
+ | | ||
+ | } | ||
+ | color = newColor; | ||
+ | setBorderColor(newColor); | ||
+ | } | ||
+ | |||
+ | | ||
+ | color = gray; | ||
+ | setBorderColor(gray); | ||
+ | notify(); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | [[.philosophenloesung: |
parallelism/deadlocks/start.1742485115.txt.gz · Zuletzt geändert: 2025/03/20 15:38 von Martin Pabst