TD1: Set values to trigger a deadlock.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 7 Mar 2018 20:15:48 +0000 (21:15 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 7 Mar 2018 20:15:48 +0000 (21:15 +0100)
And add more informative messages.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD1/exo3/BufferCirc.java
TD1/exo3/Main.java

index 1c13e54baffc0acb926b717c5d66f5bec8fddc37..68f1f1f9fd922c1eab10fcf1d1f52a336156c605 100644 (file)
@@ -32,6 +32,9 @@ public class BufferCirc {
        public synchronized void depose(Object obj) {\r
                while(isFull()) {\r
                        try {\r
+                               System.out.println("Buffer is full: " + Thread.currentThread().getName()\r
+                                    + " is waiting, size: " + nbObj);\r
+\r
                                wait();\r
                        }\r
                        catch (InterruptedException e) {}\r
@@ -47,6 +50,8 @@ public class BufferCirc {
        public synchronized Object preleve() {\r
                while(isEmpty()) {\r
                        try {\r
+                               System.out.println("Buffer is empty: " + Thread.currentThread().getName()\r
+                                    + " is waiting, size: " + nbObj);\r
                                wait();\r
                        }\r
                        catch (InterruptedException e) {}\r
index 7f0cd0eb8568ce0cdcb2f56a7f23a9d80a2462b4..28592461759aae7bbcfecec22aa8c6eb298ab0af 100644 (file)
@@ -6,7 +6,7 @@ public class Main {
 \r
 \r
        public static void main (String[] args) {\r
-               final int BUFFER_SIZE = 20;\r
+               final int BUFFER_SIZE = 1;\r
                final int PROD_NUMBER = 10;\r
                final int CONS_NUMBER = 10;\r
                BufferCirc b = new BufferCirc(BUFFER_SIZE);\r