I\'m reading Memory Barriers by Paul E. McKenney http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2010.07.23a.pdf everything is explained in great details and when
What does it mean?
It means that if you have:
read
read
read
READ BARRIER
read
read
read
then the read barrier acts as a "join point" dividing these reads into two batches. All the reads preceding the read barrier will have been done before any read following the read barrier is begun.
Which loads in bar()
must complete before the load of a
(#4) is begun?
All reads of b
(#3) are forced to precede any read of a
(#4). This means that a
is not read till after b
is no longer 0. Because foo()
uses a write barrier to ensure that a
has already been changed to 1
(#1) by the time that b
is changed (#2). The two barriers thus work together to ensure the assert statement will always succeed.