[jmm-dev] stores
Paul E. McKenney
paulmck at linux.vnet.ibm.com
Mon Feb 24 16:20:20 PST 2014
On Sun, Feb 16, 2014 at 06:00:30PM -0500, Doug Lea wrote:
>
> Memory models can generate a fair amount of excitement.
> See Linus Torvalds's post on the linux kernel list:
> https://lkml.org/lkml/2014/2/14/492
> and follow-ups with Paul McKenney. (Condolences!)
Heh! The fun continues...
> I don't think this introduces anything new with respect
> to JMM9 discussions so far though. In general, speculative
> stores and out-of-thin-air reads break basic safety properties.
> Although there still might be some related open cases
> about inserted stores, including "redundant" ones. As in:
> if (x != 0) x = 0;
> ==> x = 0; ?
One possibly interesting thing from later in the LKML discussion, though
I am not sure that it maps into the Java final-field model -- you guys
can be the judge of that. I will present it in C just for definiteness.
T1: p = &nondefault_gp;
p->a = 42;
atomic_store_release(&gp, p);
T2: p = atomic_load_explicit(&gp, memory_order_consume);
if (p != &default_gp) {
do_something_with(p);
return;
}
r1 = p->a; /* At this point, the compiler knows p == &default_gp. */
If this particular execution has only &default_gp and &nondefault_gp
as values for gp, are we guaranteed that r1==42? It would be given
the current wording in the C11 and C++11 standards. Assuming that this
example even makes sense in the context of Java final fields...
Thanx, Paul
More information about the jmm-dev
mailing list