потоки a, b, c выполняют отдельную работу (между ними не требуется синхронизация).
После завершения всех трех, нить D объединит их результаты.
so d зависит от завершения A, B и c. < /p>
.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?
Подробнее здесь: https://stackoverflow.com/questions/795 ... ultiple-re
Мобильная версия