This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix to EventQueue 5/7


Thomas Fitzsimmons wrote:

I have a question though. The current code allows the following to happen:

Thread A calls topEQ.push(newEQ) and topEQ.push executes partially but
doesn't execute this line:

newEventQueue.prev = this;

So at this point, newEQ.prev is still null (unless it was already
initialized before push was called; that shouldn't happen, but if it
did, the current code could give weird results).  If Thread B calls
newEQ.pop and executes the lines:

    if (prev == null)
      throw new EmptyStackException();

then Thread B will get an EmptyStackException, even though the method
call to push newEQ was issued before newEQ's pop call.  Is that
acceptable behaviour or should there be more synchronization to ensure
that push completes on topEQ before pop can be called on newEQ?


In our specific case this will never happen as I made sure that push and pop are called from the same thread. But even in the general case, Thread A should not inform anyone about newEQ before push() as this call is what activates this EventQueue. Actually, access to the "current" event queue is done through the one returned by getSystemEventQueue() and that is an immutable reference (always points to the original queue). This ensures all the proper locks are obtained and in the proper order.


Regards,
Fernando

--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]