[concurrency-interest] Question about "happens-before"
andreordering
Pete Soper
Pete.Soper at Sun.COM
Fri May 19 13:32:01 EDT 2006
Jeremy Manson wrote:
> Pete Soper wrote:
>
>> JLS 17.4.5 says the edge is from the end of the constructor, which
>> presumably can't be reached if an exception is thrown or the thread
>> stops making progress through the constructor. If a more tricky
>> definition of "end" is being used, then I shouldn't be surprised, but
>> will be anyway.
>
>
> The section on finalization to which 17.4.5 points clarifies this to
> mean that the constructor's "completion" happens-before the finalize
> method. In the context of the JLS, "completion" means completion via
> normal means or via exceptional (also called abrupt) means.
>
> So "end" here means via an exception, as well. We probably should have
Oh, so what I asserted to Tom is wrong. Thanks for this clarification.
If a finalizer method might run on an object for which construction is
incomplete in an arbitrary manner (by virtue of the ctor throwing an
exception), it means writing a good finalizer method is more challenging
than writing correct concurrent code for the uninitiated, or at least
just as challenging. It tells me if I ever get tempted to write a
finalizer method I'll put an edge between the last statement of the ctor
and the first statement of the finalizer as the first lines of code
written. And it's difficult to reconcile this with Bill Pugh's comment
about 4034630 on the page Tom pointed to. Is the JLS being updated for
Mustang to go along with the implementation change, or am I still not
getting it?
-Pete
> used the word "completion" in 17.4.5 to make it clearer.
>
> OTOH, if the thread hangs, then completion is never reached, as you
> point out.
>
> Jeremy
>
More information about the Concurrency-interest
mailing list