J
Joshua Cranmer
Lasse said:The class has int field called "i". As an int field, its initial value
is zero, and it is not set to 100 until after the superclass' constructor
has run. That would be Object's default constructor, which doesn't do
a lot, but it's there.
I.e., at some point the value is zero.
I grant you that.
The other thread, when started, accesses the value of the field from a
different thread than where it was assigned the values 100 and 101,
without any synchronization. Therefore the other thread should also
be able to see the stale value "0".
True, but thread startup is a synchronization event, as far as I can
read from the JLS memory model. Therefore the second thread is forced to
recognize at least the 100.