[concurrency-interest] Volatile stores in constructors, disallowed to see the default value
zhong.j.yu at gmail.com
Thu Nov 28 19:43:08 EST 2013
On Thu, Nov 28, 2013 at 5:55 PM, David Holmes <davidcholmes at aapt.net.au> wrote:
> 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.
But this part of the language is too counter-intuitive, it leads to
too many bugs; it forbids some seemingly innocent solutions (e.g.
double checked locking). The cost is too high; the benefit is unclear.
> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Martin
> 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
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
More information about the Concurrency-interest