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]; 

boost example

here understood (please correct me if wrong):

  1. if load operation thread2 precedes store operation thread1, tmp data[0].
  2. if store operation operation thread1 precedes load operation thread2, tmp data[ 1 ] because store(1,memory_order_release) thread1 ensure prior writes other memory locations visible thread2 though data[] 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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -