#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); // Store data with relaxed ordering
ready.store(true, std::memory_order_release); // Store ready with release semantics
}
void consumer() {
while (!ready.load(std::memory_order_acquire)); // Acquire ready to synchronize with producer
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;
}