I have two variables that need to be obtained in a consistent snapshot
std::atomic<int> foo;
std::shared_ptr<Bar> baz;
One writer thread, one reader thread.
Is there anything better than a mutex? The reader is going to do foo.exchange(0) and a swap (atomic for shared_ptr) for baz, but of course that doesn't guarantee consistency.
Aucun commentaire:
Enregistrer un commentaire