Let's say I have 1 counter starting at value 2, some non-atomic boolean variable and 4 threads.
//Initialization (happens before any thread execute).
std::atomic<int> count = ATOMIC_VAR_INIT(2);
bool someBoolean = false;
Thread 1:
count.fetch_sub(1, std::memory_order_release);
Thread 2:
someBoolean = true;
count.fetch_sub(1, std::memory_order_release);
Thread 3:
while(count.load(std::memory_order_acquire) != 0);
//Now, we're out of the while loop...
assert(someBoolean);
Thread 4:
while(std::atomic_thread_fence(std::memory_order_acquire),
count.load(std::memory_order_relaxed) != 0);
//Now, we're out of the while loop...
assert(someBoolean);
Is it possible that the assertions at Thread 3 or Thread 4 may fire?