How to use std::atomic for registers with fixed address

2

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.

c++
multithreading
c++11
atomicity
asked on Stack Overflow May 27, 2020 by the_summer • edited May 27, 2020 by the_summer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0