1000 mails
biweekly telephon calls
300 changesets (65 reviewed)
70,000 lines of code
thread 1 thread 2 thread 3 thread 4
a = x x = 1 y = 1 b = y
b = y a = x
Forbidden:
a==1 && b==0 a==0 && b==1
thread 1 thread 2 thread 3 thread 4
a = x x = 1 y = 1 b = y
b = y StoreLoad StoreLoad a = x
Forbidden:
a==1 && b==0 a==0 && b==1
thread 1 thread 2 thread 3 thread 4
StoreLoad StoreLoad
a = x x = 1 y = 1 b = y
StoreLoad StoreLoad
b = y a = x
public class AtomicInteger {
private volatile int value;
public AtomicInteger(int initialValue) {
value = initialValue;
}
}
Thread 1:
AtomicInteger a = new AtomicInteger(42);
Thread 2:
if (a != null) return addAndGet(1); // May return 1
Returning "1" is legal Java code.
It will never happen on x86/sparc.
The ppc64 port avoids this, too, by adding an additional barrier.
x86 | amd64 | IA64 | PPC64 | zSeries | PARISC | Sparc | |
---|---|---|---|---|---|---|---|
Linux | |||||||
Windows | |||||||
Solaris | |||||||
MacOS | |||||||
HPUX | |||||||
AIX | |||||||
AS/400 |
Java 1.4, 5, 6, 7 (and soon 8)