RE: JavaMemoryModel: Re: Java Memory Model and exceptions ?

From: David Holmes (dholmes@dstc.edu.au)
Date: Thu Aug 23 2001 - 19:41:00 EDT


Bill Pugh wrote:

> There are a number of ways in which other
> threads can be guaranteed to be correctly synchronized with the
> termination of the thread, in which case they are guaranteed to see
> the update to "field":
>
> * The ThreadGroup.uncaughtException method is correctly
> synchronized with the thread termination and must see the update to
"field".

uncaughtException is executed by the thread that is terminating, not by some
other thread which must be synchronized with the termination.
 
> * Any thread that uses Thread.join or Thread.isAlive to
> determine that the
> thread has terminated is correctly synchronized with the
> thread termination and must see the update to "field".

I agree that Thread.join should provide these semantics but as I've stated
before (as feedback on your paper) I do not agree that isAlive should
necessarily have these semantics - you could model isAlive as a read of a
volatile field, but that doesn't mean that you *have* to do that. If one
thread wants to access data modified by another thread that should now have
terminated then join() is the right way to do this, not just casual use of
isAlive.
 
> * Assuming the thread was a non-Daemon thread, all shutdown
> hooks added via Runtime.addShutdownHook are correctly synchronized
> with the thread termination and must see the update to "field".

Are you saying that a shutdown hook thread implicitly join's with every
thread that has already terminated in the VM when the shutdown hook is run?
Given that shutdown hook threads may run concurrently with user threads (via
the use of System.exit()) then it seems to me that synchronization issues
should be dealt with at the programmer level using explicit synchronization
within the shutdown hook thread and the threads that share the data used by
the shutdown hook thread. I don't see any immediate need for special
handling of shutdown hook threads with respect to the JMM. Why have you
proposed this requirement?

Cheers,
David Holmes
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:34 EDT