I’m trying to understand “sequential consistency” in terms of Java memory model. Definition from JLS, chapter 17 is not that clear to me.
I will give my vision, correct me if I’m wrong. Having program with one thread sequential consistency means that if action1 comes before action2 in the program order, than action2 should see the results of action1.
Having two threads.
Thread1:
action1
action2
Thread2:
action3
action4
If action3 sees the result of action2, than it should see the results of action1 as well.
You are correct; sequential consistency means that each action is executed atomically and is immediately visible to all threads. It is as if you interleaved all threads into a single thread, executing actions one by one.
Be careful to note that sequential consistency is not the way Java Memory Model actually works.
Quote from 17.4.3, Programs and Program Order: