Tutorial by Examples

int x, y; bool ready = false; void init() { x = 2; y = 3; ready = true; } void use() { if (ready) std::cout << x + y; } One thread calls the init() function while another thread (or signal handler) calls the use() function. One might expect that the use() function ...
The example above can also be implemented with fences and relaxed atomic operations: int x, y; std::atomic<bool> ready{false}; void init() { x = 2; y = 3; atomic_thread_fence(std::memory_order_release); ready.store(true, std::memory_order_relaxed); } void use() { if (re...

Page 1 of 1