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
When you enter a synchronized block of code you pass the "read barrier" and when it is exited you pass the "write barrier".
Is is used in reference to volatile attributes, and give an indication when Threads need to update their values of the volatile attributes. They should update it when they are passing the read barrier if anyone else passed the write barrier.
Similar reading from a volatile attribute makes yout thread pass the read barrier and writing to a volatile attribute makes you pass the write barrier, hence much more fine grained than a synchronized block.