...
Program order is the execution order that is expected when a single thread is running the statements sequentially, as written in a method. Even if statements execute in the expected order (program order), caching can prevent the latest values from being reflected in the main memory.
Wiki Markup |
---|
2. [Sequential consistency|BB. Definitions#sequential consistency]: This property provides a very strong guarantee that the compiler will not optimize away or reorder any statements. It guarantees that the program is free from data races. It also ensures that each access is atomic and immediately visible to other threads. However, "Sequential consistency and/or freedom from data races still allows errors arising from groups of operations that need to be perceived atomically and are not." \[[JLS 05|AA. Java References#JLS 05]\]. |
The use of sequential consistency as the sole memory model mechanism makes it easy for a programmer to follow the logic, however, introduces a performance penalty. Implementing synchronization correctly guarantees that all executions of the program are sequentially consistent. Consequently, synchronizing code is more expensive than using volatile
variables which guarantee a weaker form of sequential consistency.
...