On 05/14/2008 10:55 AM, Emmanuel Lecharny wrote:
Sangjin Lee wrote:
Hmm... Could you share a simple example of a non-volatile variable that
respects the volatile contract?
any boolean.
This is incorrect. Changes made to a boolean that is not volatile may
never become visible in another thread.
Adding volatile changes the contract thus:
Any data visible to thread A at the time the volatile is written to (by
thread A), will be visible in thread B at the time that the *same* volatile
is read from (by thread B).
This is a simplified version - but please do read Java Concurrency In
Practice to get the longer explanation.
- DML