Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6801020
Votes 0
Synopsis Concurrent Semaphore release may cause some require thread not signaled
Category java:classes_util_concurrent
Reported Against
Release Fixed 7(b55), 6-open(b16) (Bug ID:2175059)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 6241823 , 6803402 , 6822370
Submit Date 04-FEB-2009
Description
FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP SP3

EXTRA RELEVANT SYSTEM CONFIGURATION :
P4 2.8HT

A DESCRIPTION OF THE PROBLEM :
Semaphore initial state 0. 4 threads run 4 tasks.
Two threads run acquire semaphore once, the other two threads run release semaphore once.
One possible result is the semaphore state value is 1 and one thread still waiting.

The possible reason:
When AbstractQueuedSynchronizer#release are called, head.waitStatus may be 0 because the previous acquire thread may run at AbstractQueuedSynchronizer#doAcquireShared before setHeadAndPropagate is called.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The given executable test case will hung. Suggest using dual-core CPU or HT CPU to reproduce.


REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
import java.util.concurrent.Semaphore;

public class TestSemaphore {

    private static Semaphore sem = new Semaphore(0);

    private static class Thread1 extends Thread {
        @Override
        public void run() {
            sem.acquireUninterruptibly();
        }
    }

    private static class Thread2 extends Thread {
        @Override
        public void run() {
            sem.release();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10000000; i++) {
            Thread t1 = new Thread1();
            Thread t2 = new Thread1();
            Thread t3 = new Thread2();
            Thread t4 = new Thread2();
            t1.start();
            t2.start();
            t3.start();
            t4.start();
            t1.join();
            t2.join();
            t3.join();
            t4.join();
            System.out.println(i);
        }
    }
}

---------- END SOURCE ----------
Posted Date : 2009-02-04 09:34:51.0
Work Around
N/A
Evaluation
There was a race condition that could prevent a releaseShared from being propagated through to a parked thread, leaving the thread parked while a permit existed.

Fix supplied by Doug Lea, and Martin Buccholz.
Posted Date : 2009-03-31 04:14:50.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang