C ++ Atomics erwerben/freisetzung und RMWC++

Programme in C++. Entwicklerforum
Anonymous
 C ++ Atomics erwerben/freisetzung und RMW

Post by Anonymous »

Threads A, B, C erledigen separate Arbeiten (zwischen ihnen ist keine Synchronisation erforderlich).int a = 0;
int b = 0;
int c = 0;
std::atomic_int D_dependencies{ 3 };
< /code>
thread A :
a = 1;
D_dependencies.fetch_sub(1, std::memory_order_release);
< /code>
thread B :
b = 1;
D_dependencies.fetch_sub(1, std::memory_order_release);
< /code>
thread C :
c = 1;
D_dependencies.fetch_sub(1, std::memory_order_release);
< /code>
thread D :
if(D_dependencies.load(std::memory_order_acquire) == 0)
{
assert(a + b + c == 3);
}
< /code>
My understanding is that RMW operations like fetch_sub form a "release sequence" and so the load in thread D should observe all writes if it loads 0 from the atomic variable.
Am I correct?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post