Is there any case that the atomicity of std::atomic is not guaranteed, when is_lock_free() == false?

Even if is_lock_free() == false , typically maybe, the atomicity of std::atomic can be guaranteed. Is that right? I wander that there are computer environments or cases where the atomicity is not guaranteed, when is_lock_free() == false. >Solution : Non-lock-free atomics aren’t address-free, so shared memory between two processes would mean they don’t respect each… Read More Is there any case that the atomicity of std::atomic is not guaranteed, when is_lock_free() == false?

Is my understanding of __ATOMIC_SEQ_CST correct? (I'd like to write a mutex with it + atomics)

For fun I’m writing my own threading library used by me and a friend or two. First thing I’d like to write is a mutex It appears I’m generating the assembly I want. __atomic_fetch_add seems to generate lock xadd and __atomic_exchange seems to generate xchg (not cmpxchg). I use both with __ATOMIC_SEQ_CST (for now I’ll… Read More Is my understanding of __ATOMIC_SEQ_CST correct? (I'd like to write a mutex with it + atomics)

std::atomic passed as a const reference to a non-atomic type

Let’s say I have this application: #include <atomic> #include <thread> #include <iostream> #include <chrono> void do_something(const std::atomic<bool>& stop) { while (!stop) { std::cout << "Doing stuff…" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1)); } } int main() { std::atomic<bool> stop { false }; std::thread wait([&stop] { std::this_thread::sleep_for(std::chrono::seconds(10)); stop = true; }); do_something(stop); wait.join(); } This works as expected. The… Read More std::atomic passed as a const reference to a non-atomic type