<AWT Dev> [7u6] Review request for 7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater

Oleg Pekhovskiy oleg.pekhovskiy at oracle.com
Wed Jul 11 08:24:40 PDT 2012


Hi!

Please review the fix for CR:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7177040

Webrev:
http://cr.openjdk.java.net/~bagiras/7u6/7177040.1

The idea of the fix is that there are two concurrent threads that try to 
get two synchronization objects EventQueue.pushPopLock and 
PostEventQueue itself.
For NetBeans these threads are (EDT & WarmUp) or (EDT & TimerQueue).
Problem happens when EDT is interrupted and goes to 
EventQueue.detachDispatchThread() where EventQueue.pushPopLock is owned and
EDT is waiting to own PostEventQueue when calling 
SunToolkit.isPostEventQueueEmpty() -> PostEventQueue.noEvents().
At the same time another thread calls EventQueue.postEvent() that calls 
EventQueue.flushPendingEvents() -> PostEventQueue.flush() where 
PostEventQueue is owned
and another thread is waiting to own EventQueue.pushPopLock when calling 
EventQueue.postEvent() -> EventQueue.postEventPrivate().

To avoid potential deadlock I moved synchronization out of postEvent()'s 
cycle in PostEventQueue.flush(),
but to be clear about the existence of Events that are not posted to 
EventQueue yet I added PostEventQueue.isPending flag that is true until 
the end of the cycle.

There are only two classes that utilize PostEventQueue.flush() method: 
SunToolkit.flushPendingEvents() and SunToolkitSubclass.flushPendingEvents().
They are both synchronized by static SunToolkit.flushLock. That 
eliminates the situation when we have overlapped calls of 
PostEventQueue.flush().

Thanks,
Oleg



More information about the awt-dev mailing list