This is a question about the memory order listed in 'c++ concurrency in action'.
First, in listing 5.7; the consequence can be:
Thread A :
x.store(true, release)
Thread B :
x.load(acquire)
returns true,y.load(acquire)
returns falseThread C :
y.load(acquire)
returns true,x.load(acquire)
returns falseThread D :
y.store(true, release)
On the other hand, by 'release sequence':
- thread A's store -> thread B's x_load and
- by release sequence, -> thread C's x_load
- so thread C's x_load must be true, if thread B's y_load is false.
So I think it should be
Thread B :
x.load(acquire)
returns true,y.load(acquire)
returns trueThread C :
y.load(acquire)
returns true,x.load(acquire)
returns false
or
Thread B :
x.load(acquire)
returns true,y.load(acquire)
returns falseThread C :
y.load(acquire)
returns true,x.load(acquire)
returns true
Another question:
In listing 7.12 there is a paragraph,
'the easy way to do this is to make the
fetch_add()
in the successful-return branch usestd::memory_order_release
and thefetch_add()
in the loop-again branch usestd::memory_order_acquire
. However, this is still overkill: only one thread does the delete , so only that thread needs to do an acquire operation. Thankfully, becausefetch_add()
is read-modify-write operation, it forms part of the release sequence, so you can do that with an additionalload()
.'
I don't know what this paragraph means; where is the 'release sequence' ?