Memory Order Acquire-Release
Given the following code with C++ atomics:
std::atomic<int> data{0};
std::atomic<bool> ready{false};
// Thread 1
data.store(42, std::memory_order_relaxed);
ready.store(true, std::memory_order_release);
// Thread 2
if (ready.load(std::memory_order_acquire)) {
int value = data.load(std::memory_order_relaxed);
}
What value is guaranteed to be read by Thread 2?
Sign in to answer questions and track your progress
Sign In