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

Robert Kuhar robertkuhar at yahoo.com
Fri May 19 11:48:23 EDT 2006


> 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.

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 


More information about the Concurrency-interest mailing list