-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b31
-
x86, sparc
-
solaris_9, windows_xp
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2124413 | 5.0u6 | Martin Buchholz | P3 | Resolved | Fixed | b02 |
FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
Consecutive calls to Semaphore.tryAcquire(int permits, long timeout, TimeUnit unit) on a fair semaphore with no permits available causes infinite loop.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public static void main(String[] args) throws Exception {
Semaphore sem = new Semaphore(0,true);
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println("OK!");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
false
false
OK!
ACTUAL -
false
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There is no error message, as the second call to tryAcquire() never returns.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.concurrent.*;
public class Test {
public static void main(String[] args) throws Exception {
Semaphore sem = new Semaphore(0,true);
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println("OK!");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use fair semaphores (changing the above case to new Semaphore(0,false) works)
###@###.### 2005-03-16 22:22:49 GMT
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
Consecutive calls to Semaphore.tryAcquire(int permits, long timeout, TimeUnit unit) on a fair semaphore with no permits available causes infinite loop.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public static void main(String[] args) throws Exception {
Semaphore sem = new Semaphore(0,true);
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println("OK!");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
false
false
OK!
ACTUAL -
false
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There is no error message, as the second call to tryAcquire() never returns.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.concurrent.*;
public class Test {
public static void main(String[] args) throws Exception {
Semaphore sem = new Semaphore(0,true);
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println(sem.tryAcquire(100,TimeUnit.MILLISECONDS));
System.out.println("OK!");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use fair semaphores (changing the above case to new Semaphore(0,false) works)
###@###.### 2005-03-16 22:22:49 GMT
- backported by
-
JDK-2124413 Infinite loop in timed Semaphore.tryAcquire
-
- Resolved
-
- duplicates
-
JDK-6289795 "fair" lock policy in ReentrantLock may cause busy hang
-
- Closed
-
- relates to
-
JDK-6801020 Concurrent Semaphore release may cause some require thread not signaled
-
- Closed
-