From 4b705a7a399b380217baca9b23b911fc8bc7fe19 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Mar 2018 21:15:48 +0100 Subject: [PATCH] TD1: Set values to trigger a deadlock. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit And add more informative messages. Signed-off-by: Jérôme Benoit --- TD1/exo3/BufferCirc.java | 5 +++++ TD1/exo3/Main.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/TD1/exo3/BufferCirc.java b/TD1/exo3/BufferCirc.java index 1c13e54..68f1f1f 100644 --- a/TD1/exo3/BufferCirc.java +++ b/TD1/exo3/BufferCirc.java @@ -32,6 +32,9 @@ public class BufferCirc { public synchronized void depose(Object obj) { while(isFull()) { try { + System.out.println("Buffer is full: " + Thread.currentThread().getName() + + " is waiting, size: " + nbObj); + wait(); } catch (InterruptedException e) {} @@ -47,6 +50,8 @@ public class BufferCirc { public synchronized Object preleve() { while(isEmpty()) { try { + System.out.println("Buffer is empty: " + Thread.currentThread().getName() + + " is waiting, size: " + nbObj); wait(); } catch (InterruptedException e) {} diff --git a/TD1/exo3/Main.java b/TD1/exo3/Main.java index 7f0cd0e..2859246 100644 --- a/TD1/exo3/Main.java +++ b/TD1/exo3/Main.java @@ -6,7 +6,7 @@ public class Main { public static void main (String[] args) { - final int BUFFER_SIZE = 20; + final int BUFFER_SIZE = 1; final int PROD_NUMBER = 10; final int CONS_NUMBER = 10; BufferCirc b = new BufferCirc(BUFFER_SIZE); -- 2.34.1