From: Jérôme Benoit Date: Wed, 7 Mar 2018 20:15:48 +0000 (+0100) Subject: TD1: Set values to trigger a deadlock. X-Git-Url: https://git.piment-noir.org/?p=TD_SR.git;a=commitdiff_plain;h=4b705a7a399b380217baca9b23b911fc8bc7fe19;hp=8084e5ebb29e8b6d14109f8b06ef6f01db931609 TD1: Set values to trigger a deadlock. And add more informative messages. Signed-off-by: Jérôme Benoit --- 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);