I am looking into how a synchronized and volatile variable works in java and i came across a concept called read and write barrier . Can anyone help me to understand the mea
( the answers above are quite complete), I just want to demonstrate the concept with a simple scheme
Thread 1 Thread 2
|
|
| |
| |
| Everything Thread 1 |
| wrote before here |
| |
| |
_ _ _ _ _ _ _ _ _ _ |
( write barrier) (happens before) (read barrier) |
| _ _ _ _ _ _ _ _
|
| is guaranteed |
| to be visible to |
| Thread 2 |
| |