Re: Two more multithreading questions
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 16:59:10 -0800
A. Bolmarcich wrote:
On 2007-01-30, Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx> wrote:Thank you very much for your response but it doesn't really answer my question. As to the immutable, I'm not muting. So let me set the scenario again.
Class with instance variable that is reference to Integer. One thread makes new Integers and assigns them to the instance variable. The other thread calls some method on the Integer. I want to know if making the variable volatile will guarantee that the second thread always sees the latest integer created by the first thread.
No, volatile does not "guarantee that the second thread always sees the
latest integer created by the first thread". What volatile guarantees
is that when one thread executes assignment statements to volatile
variables other threads will see the effect of the assignment
statements in the same order that they were executed.
It is possible that one thread starts executing an assignment statement
to a volatile variable and very slightly later another thread starts
executing a statement that uses the value of that variable. The second
thread may get the value of the variable before latest assignment
statment by the first thread. A basic problem is that without some
form of synchronization between theads (not necessarily by the Java
synchronize statement) there is no definite time ordering of operations
between threads.
This is why I keep asking these questions because I get different answers. Can you explain what is meant in the documentation then by:
JLS 17.4.4 Synchronization Order
....
A write to a volatile variable (§8.3.1.4) v synchronizes-with all subsequent reads of v by any thread (where subsequent is defined according to the synchronization order).
Thanks very much,
--
Knute Johnson
email s/nospam/knute/
.
- Follow-Ups:
- Re: Two more multithreading questions
- From: A. Bolmarcich
- Re: Two more multithreading questions
- References:
- Two more multithreading questions
- From: Knute Johnson
- Re: Two more multithreading questions
- From: Patricia Shanahan
- Re: Two more multithreading questions
- From: Knute Johnson
- Re: Two more multithreading questions
- From: Daniel Pitts
- Re: Two more multithreading questions
- From: Knute Johnson
- Re: Two more multithreading questions
- From: A. Bolmarcich
- Two more multithreading questions
- Prev by Date: Re: Thread safe IO?
- Next by Date: Re: Cannot find main class
- Previous by thread: Re: Two more multithreading questions
- Next by thread: Re: Two more multithreading questions
- Index(es):
Relevant Pages
|