Commit 605d10f7 by Fernando Nasser Committed by Fernando Nasser

EventQueue.java (pop): Prevent racing condition to add events to the queue out…

EventQueue.java (pop): Prevent racing condition to add events to the queue out of order by acquiring...

        * java/awt/EventQueue.java (pop): Prevent racing condition to add
        events to the queue out of order by acquiring locks in the proper
        order and not by releasing one before acquiring the other.

From-SVN: r76161
parent 8f9f8d71
2004-01-19 Fernando Nasser <fnasser@redhat.com> 2004-01-19 Fernando Nasser <fnasser@redhat.com>
* java/awt/EventQueue.java (pop): Prevent racing condition to add
events to the queue out of order by acquiring locks in the proper
order and not by releasing one before acquiring the other.
2004-01-19 Fernando Nasser <fnasser@redhat.com>
* gnu/java/awt/peer/gtk/TestAWT.java (DialogWindow): Make text not * gnu/java/awt/peer/gtk/TestAWT.java (DialogWindow): Make text not
visible so that dialog can be reused. visible so that dialog can be reused.
......
...@@ -358,32 +358,34 @@ public class EventQueue ...@@ -358,32 +358,34 @@ public class EventQueue
if (prev == null) if (prev == null)
throw new EmptyStackException(); throw new EmptyStackException();
// Don't synchronize both this and prev at the same time, or deadlock could /* The order is important here, we must get the prev lock first,
// occur. or deadlock could occur as callers usually get here following
prev's next pointer, and thus obtain prev's lock before trying
to get this lock. */
synchronized (prev) synchronized (prev)
{ {
prev.next = next; prev.next = next;
if (next != null) if (next != null)
next.prev = prev; next.prev = prev;
}
synchronized (this) synchronized (this)
{
int i = next_out;
while (i != next_in)
{ {
prev.postEvent(queue[i]); int i = next_out;
next_out = i; while (i != next_in)
if (++i == queue.length) {
i = 0; prev.postEvent(queue[i]);
} next_out = i;
// Empty the queue so it can be reused if (++i == queue.length)
next_in = 0; i = 0;
next_out = 0; }
// Empty the queue so it can be reused
next_in = 0;
next_out = 0;
// Tell our EventDispatchThread that it can end execution // Tell our EventDispatchThread that it can end execution
dispatchThread.interrupt (); dispatchThread.interrupt ();
dispatchThread = null; dispatchThread = null;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment