Volatile
Http://www.cnblogs.com/aigongsi/archive/2012/04/01/2429166.html
Some of the uses of the volatile keyword are described earlier, so let's look at how volatile guarantees visibility and suppresses command reordering.
The following is an excerpt from the in-depth understanding of Java Virtual machines:
"Observing the addition of the volatile keyword and the assembly code generated when the volatile keyword was not added, a lock prefix instruction is added when adding the volatile keyword"
The lock prefix instruction is actually equivalent to a memory barrier (also a memory fence), and the memory barrier provides 3 functions:
1) It ensures that the command reordering does not place the instructions behind the memory barrier and does not queue the preceding instruction behind the memory barrier, i.e., the operation in front of the memory barrier is completed when the command is executed;
2) It forces the modification of the cache to be immediately written to main memory;
3) If it is a write operation, it causes the corresponding cache line in other CPUs to be invalid.
Multi-threaded instruction reordering
http://blog.csdn.net/beiyetengqing/article/details/49580559
Compilers and processors follow data dependencies when reordering, and compilers and processors do not change the order in which two operations exist that have data dependencies
Java volatile keywords