CppMem: Atomics with a Relaxed Semantic
This lesson gives an overview of atomics with a relaxed semantic used in the context of CppMem.
We'll cover the following...
With the relaxed semantic, we don’t have synchronization or ordering constraints on atomic operations; only the atomicity of the operations is guaranteed.
Press + to interact
// ongoingOptimisationRelaxedSemantic.cpp#include <atomic>#include <iostream>#include <thread>std::atomic<int> x{0};std::atomic<int> y{0};void writing(){x.store(2000, std::memory_order_relaxed);y.store(11, std::memory_order_relaxed);}void reading(){std::cout << y.load(std::memory_order_relaxed) << " ";std::cout << x.load(std::memory_order_relaxed) << std::endl;}int main(){std::thread thread1(writing);std::thread thread2(reading);thread1.join();thread2.join();};
For the ...
Access this course and 1400+ top-rated courses and projects.