repositories
/
TD_SR.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TD1: Explain and fix the deadlock in exo3.
[TD_SR.git]
/
TD1
/
exo3
/
BufferCirc.java
diff --git
a/TD1/exo3/BufferCirc.java
b/TD1/exo3/BufferCirc.java
index 1c13e54baffc0acb926b717c5d66f5bec8fddc37..ebfb2877016fdc978bf4e47b6d61ba9b9e2cb6c3 100644
(file)
--- a/
TD1/exo3/BufferCirc.java
+++ b/
TD1/exo3/BufferCirc.java
@@
-32,6
+32,9
@@
public class BufferCirc {
public synchronized void depose(Object obj) {
\r
while(isFull()) {
\r
try {
\r
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
wait();
\r
}
\r
catch (InterruptedException e) {}
\r
@@
-40,13
+43,15
@@
public class BufferCirc {
tampon[prem] = obj;
\r
prem = (prem + 1) % taille;
\r
//System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);
\r
tampon[prem] = obj;
\r
prem = (prem + 1) % taille;
\r
//System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);
\r
- notify();
\r
+ notify
All
();
\r
}
\r
\r
\r
public synchronized Object preleve() {
\r
while(isEmpty()) {
\r
try {
\r
}
\r
\r
\r
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
wait();
\r
}
\r
catch (InterruptedException e) {}
\r
@@
-56,7
+61,7
@@
public class BufferCirc {
outObj = tampon[der];
\r
der = (der + 1) % taille;
\r
//System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);
\r
outObj = tampon[der];
\r
der = (der + 1) % taille;
\r
//System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);
\r
- notify();
\r
+ notify
All
();
\r
return outObj;
\r
}
\r
\r
return outObj;
\r
}
\r
\r