Browse Source

Änderungen 05.12.2023 um 14:44

master
leonmcfly 1 year ago
parent
commit
582ed1a694
2 changed files with 23 additions and 5 deletions
  1. 16
    5
      src/DiningPhilosophers/Fork.java
  2. 7
    0
      src/DiningPhilosophers/ForkTest.java

+ 16
- 5
src/DiningPhilosophers/Fork.java View File

@@ -10,16 +10,27 @@ public class Fork {
}

public int getId(){
return id;
}

public boolean take(){

synchronized (this){
if (inUse){
return false;
}
inUse = true;
try {
Thread.sleep(1000);
}catch (InterruptedException e){
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
}
return true
}
}

public void put(){

synchronized(this){
inUse = false;
}
}


}

+ 7
- 0
src/DiningPhilosophers/ForkTest.java View File

@@ -0,0 +1,7 @@
package Prog3.src.DiningPhilosophers;

import static org.junit.jupiter.api.Assertions.*;

class ForkTest {

}

Loading…
Cancel
Save