[concurrency-interest] reordering

Jeremy Manson jmanson at cs.purdue.edu
Fri May 19 12:06:15 EDT 2006


If you are looking at a single thread in isolation, program order means 
the order in which the statements in the source code occur, and the 
order in which the bytecodes occur.

> But back to your statement. I don't agree. The memory model *does*
> have relevance to single threaded programs, as the "constructor
> completion happens-before finalizer runs" rule shows us. At least I
> hope it does! It would be terrible if the finalizer thread can say
> "well, we're tired of waiting: lets just run this thing anyway."  Put
> a different way, even if the developer thinks they have a 100%
> single-threaded application, it's not running in a single-threaded
> environment.

I think that, rather than saying that the memory model has relevance to 
single-threaded programs, I might instead say that there are no 
single-threaded programs in Java.  Finalizers are a good example of why 
this is true - an object's finalizer will never run in the same thread 
in which the object was constructed, and there is nothing in the spec 
that suggests that it might.  This is one of the reasons why having some 
understanding of multithreaded programming and the memory model is so 

Kazimierz's original code should do what it was intended to do because, 
once again, of the precision of exceptions.  Again, the write to the 
committed variable, for example, will only occur if the exception is not 


More information about the Concurrency-interest mailing list