Threads and synchronization

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.
 
L

Lasse Reichstein Nielsen

Joshua Cranmer said:
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.

Ack, true. I had missed the implicit synchronization between a thread
starter and the started thread.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Merge sort and threads 0
Threads - synchronization 7
Threads and synchronized methods 5
notify() and wait() 8
Synchronization of the constructor 13
Question on Threads 4
Synchronization question... 2
threads and GUIs 18

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top