Final version

pull/2/head
obaya 2025-05-03 20:09:04 +02:00
parent 3cee7198b9
commit 285200c86e
1 changed files with 33 additions and 21 deletions

View File

@ -3,6 +3,7 @@ package pp;
import java.util.Random;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class Philosopher extends Thread implements IPhilosopher {
private int seat;
@ -20,6 +21,12 @@ public class Philosopher extends Thread implements IPhilosopher {
this.stopped = false;
}
public static void main(String... args) {
// TODO
}
@Override
public void run() {
try {
@ -36,8 +43,11 @@ public class Philosopher extends Thread implements IPhilosopher {
table.lock();
try {
while(this.links.eating || this.rechts.eating)
while (this.links.eating || this.rechts.eating) {
log(seat, " : isst gerade!");
this.condition.await();
}
this.eating = true;
} finally {
table.unlock();
@ -58,7 +68,6 @@ public class Philosopher extends Thread implements IPhilosopher {
}
}
@Override
public void setLeft(IPhilosopher left) {
// TODO Auto-generated method stub
@ -92,4 +101,7 @@ public class Philosopher extends Thread implements IPhilosopher {
this.stopped = true;
interrupt();
}
}