Re: ThreadPoolExecutor backport



Robert Klemme wrote:
I faintly remember articles
about the flaws of the Java memory model before Java 5 and I believe
volatile handling was one of them.  Or am I mixing up something?

What you are remembering is that 'volatile' prior to Java 5 only
guaranteed visibility of changes through the volatile variable
itself. Other changes might not have propagated.

So given

class Foo
{
volatile int flag;
int value; // not volatile
...
}

the old memory model would guarantee visbility of changes to 'flag',
but not other changes. Code like:

value += 17;
flag = 1;

in one thread guaranteed that another thread would see 'flag' as 1,
but not that it would see the change in 'value'. In the new memory
model, the change to 'value' /happens-before/ the change to 'flag', so
it is visible across threads.

--
Lew
.



Relevant Pages

  • Re: ThreadPoolExecutor backport
    ... AFAIK the implementation you are using preceded Java 5 so it is not ... Are you sure with regard to "volatile"? ... about the flaws of the Java memory model before Java 5 and I believe ... difference is, as stated, not relevant to the snippet. ...
    (comp.lang.java.programmer)
  • Re: Function prefix comments in C files
    ... >> volatile keyword tells the compiler that he cannot assume anything about ... >> SW ISR. ... > example, if there is a lot of data, maybe a single volatile "update" flag ... use reentrancy (assuming timer ISRs and/or other code needs to call the ...
    (comp.arch.embedded)
  • Re: About volatile qualifier
    ... In an article about volatile qualifier there is a small code by which the ... void Wakeup{flag = true;} ... compiler optimizes access to that variable by caching it in a register. ... Thread-1 will never get the actual value of the flag and loop forever." ...
    (microsoft.public.vc.language)
  • Re: is assignment atomic/thread safe?
    ... Peter Duniho wrote: ... Thomas Pornin wrote: ... If thread B reads the volatile variable, then it will see the change ... To do otherwise would violate Java semantics. ...
    (comp.lang.java.programmer)
  • Re: Thread safe access to elements of a growing array without synchronization
    ... makes volatile useful. ... In the old memory model, ... and reading from a volatile field has the same memory ... almost to the level of synchronization. ...
    (comp.lang.java.programmer)