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

Pete Soper Pete.Soper at Sun.COM
Fri May 19 13:18:30 EDT 2006

Robert Kuhar wrote:
>>This seemed quite clear the first time. More fundamentally, if the 
>>constructor never completes, the finalizer's running is impossible, right?
> The finalizer running in either the success or failure of the constructor is
> the vunerability the example is trying to solve.  Somewhere on the show-floor,
> as I was running around trying to gain enlightenment, the assertion was made
> that the root cause of this problem is exactly that; the constructor failed,
> but the object existed for the GC to find and finalize.

I'm slow on the uptake some times (by approximately 7 1/2 years) and 
missed understanding what started this mail thread. Thanks to Tom for 
making the bug to do with this apparent, and to Jeremy for explaining 
the exception handling (probably) being the big roadblock for preventing 
the code motion in that example constructor.

And I just spotted Bill Pugh's comment about the older of the two bugs. 
I do need something for my stomach.


> It appears that what makes the example thread-safe is a special case of the
> relationship between the constructor and the finalizer of which I was unaware. 
>   "...or the constructor won't appear to have happenned-before the finalizer
> (and the spec says it must)." - Giuliano Mega
> So that now makes sense.  However, it still strikes me as odd that a similar
> pattern is held up as "what not to do" in the discussions of double-checked
> locking but, for this case of constructor to finalizer, is somehow correct.
> What I really need is "the Visible VM".  Much like "the Visible V8" of my
> childhood.  You can do things to it, and watch the effects directly rather than
> theorize about what can happen.  Now that would be really useful.
> Thanks to all for their replies.  I think I'll just make my classes final and
> that's that.  No need to worry about malicious subclasses exploiting finalizer
> behavior.  Inheritence be damned!  I'm joking, I like inheritence.
> Bob
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list