#include <iostream>
#include <atomic>
#include <thread>
std::atomic<int> data(0);
std::atomic<bool> ready(false);
void producer() {
data.store(42, std::memory_order_relaxed);
ready.store(true, std::memory_order_release); // Release: Ensures data is visible
}
void consumer() {
while (!ready.load(std::memory_order_acquire)); // Acquire: Waits for release
std::cout << "Data: " << data.load(std::memory_order_relaxed) << std::endl;
}
int main() {
std::thread t1(producer);
std::thread t2(consumer);
t1.join();
t2.join();
return 0;
}