[concurrency-interest] Question about "happens-before" and reordering

Giuliano Mega giuliano.mega at gmail.com
Thu May 18 21:29:44 EDT 2006


Hi,

> The reply was that somehow the Exception that can come out of securityCheck()
> establishes some "happens-before" and therefore this code is thread-safe.  I am
> skeptical as I have never heard that before (or didn't understand it if I did).

The language spec says that there is a happens-before edge that goes
from the end of the constructor to the start of the finalizer of that
same object. (see
http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.4.5)

So, unless I'm talking nonsense (in which case I would politely ask
for someone to correct me), this means that what happens at the
constructor must be visible at the finalizer, for all threads.
Although the instructions may be reordered, the resulting execution
must be "legal" in the sense that it must reflect a possible
execution. In your example, if an exception is thrown at the security
check, then the flag must be seen as false at the finalizer as it is
the only legal option.

Best,

-- 
Giuliano Mega <giuliano at ime.usp.br>



More information about the Concurrency-interest mailing list