As far as I understand it std::atomic<uint32_t> foo
will create an atomic variable for me, but the actual memory location will be decided by the linker.
On the other hand std::atomic<uint32_t*> bar
will create an atomic pointer, i.e. the pointer itself is protected, but not the target it points to.
I was wondering if it is also possible to create an atomic variable protecting a known memory address (e.g. a register of a device). Something like
uint32_t register_addr = 0xdeadbeef;
std::atomic<uint32_t> register(register_addr);
So that device register accesses from different threads are automatically serialized.
User contributions licensed under CC BY-SA 3.0