How do I make memory stores in one thread “promptly” visible in other threads?
问题 Suppose I wanted to copy the contents of a device register into a variable that would be read by multiple threads. Is there a good general way of doing this? Here are examples of two possible methods of doing this: #include <atomic> volatile int * const Device_reg_ptr = reinterpret_cast<int *>(0x666); // This variable is read by multiple threads. std::atomic<int> device_reg_copy; // ... // Method 1 const_cast<volatile std::atomic<int> &>(device_reg_copy) .store(*Device_reg_ptr, std::memory