c++ - Boost memory_order_consume Example -
i looking @ boost example regarding atomic operations , happens-before relationship, , i'm bit confused. in "happens-before through release , consume" section, there following example erroneous, cannot see :
atomic<int> a(0); complex_data_structure data[2]; thread1:
data[1] = ...; /* */ a.store(1, memory_order_release); thread2:
int index = a.load(memory_order_consume); complex_data_structure tmp; if (index == 0) tmp = data[0]; else tmp = data[1]; here understood (please correct me if wrong):
- if
loadoperation thread2 precedesstoreoperation thread1,tmpdata[0]. - if
storeoperation operation thread1 precedesloadoperation thread2,tmpdata[ 1 ]becausestore(1,memory_order_release)thread1 ensure prior writes other memory locations visible thread2 thoughdata[]not computationally-dependent on index.
can please clarify error they're talking about?
with release/consume, writes variables prior store(release) guaranteed visible @ matching load(consume) if, , if, variables dependent on variable used in store(release)-load(consume) pair.
by using int literals index data[] dependency has been broken, writes data[] not guaranteed visible after a.load(consume).
Comments
Post a Comment