[concurrency-interest] Volatile stores in constructors, disallowed to see the default value

David Holmes davidcholmes at aapt.net.au
Thu Nov 28 18:55:04 EST 2013


Martin,

Guaranteeing safe-publication has been discussed before - please search here
or on JMM list. Costs vary by platform.

JDK classes do continue to have safe-publication bugs (fixed on just last
week) but this is not because anything is assumed as such, just the regular
ignorance that things can be published unsafely.

David
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Martin
Buchholz
  Sent: Friday, 29 November 2013 9:49 AM
  To: Doug Lea
  Cc: concurrency-interest
  Subject: Re: [concurrency-interest] Volatile stores in constructors,
disallowed to see the default value







  On Wed, Nov 27, 2013 at 11:26 AM, Doug Lea <dl at cs.oswego.edu> wrote:

    Right. To summarize:


    * Programmers do not expect that even though final fields are
specifically
    publication-safe, volatile fields are not always so.




  Many programmers intuitively expect *all* fields assigned in constructors
to be publication-safe....

    * For various implementation reasons, JVMs arrange that
    volatile fields are publication safe anyway, at least in
    cases we know about.




  ... and at least on x86 with current JVMs, naive programmers are right -
*all* fields are in practice publication-safe.
  ... and I believe even some JDK classes depend on this being true ...


  Which suggests we could actually expand final field guarantees to all
fields in the spec.  What's the actual expected loss of performance on
current hardware?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20131129/8202b0a2/attachment.html>


More information about the Concurrency-interest mailing list