From a0f83a8672c003576fa8449af6f25816590d0766 Mon Sep 17 00:00:00 2001 From: Jan Bachmann <3010330@stud.hs-mannheim.de> Date: Tue, 29 Oct 2024 10:38:57 +0100 Subject: [PATCH] Final --- pp.A1-CondPhilosophers/src/main/java/pp/Philosopher.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pp.A1-CondPhilosophers/src/main/java/pp/Philosopher.java b/pp.A1-CondPhilosophers/src/main/java/pp/Philosopher.java index 247ec3b..3893d9c 100644 --- a/pp.A1-CondPhilosophers/src/main/java/pp/Philosopher.java +++ b/pp.A1-CondPhilosophers/src/main/java/pp/Philosopher.java @@ -52,8 +52,12 @@ public class Philosopher extends Thread implements IPhilosopher { log("left nor right eating"); this.eating = true; log("eating"); - Thread.sleep(this.random.nextInt(MAX_EATING_DURATION_MS)); - + } finally { + table.unlock(); + } + Thread.sleep(this.random.nextInt(MAX_EATING_DURATION_MS)); + this.table.lock(); + try { this.eating = false; this.left.condition.signal(); this.right.condition.signal();