3 ms·
Assuming that shared_ptrs themselves are thread safe is a common error :(. The standard (and boost) does provide additional operations to manipulate shared poi
by gpderetta 6y ago
Assuming that shared_ptrs themselves are thread safe is a common error :(.
The standard (and boost) does provide additional operations to manipulate shared pointers themselves in a thread safe way, for example void atomic_store( std::shared_ptr<T>* p,
std::shared_ptr<T> r ) but they are not guaranteed to be lock free (and they are not in practice) and have been deprecated in C++20.
It seems that your scenario would be best be handled via hazard pointers, but if you have an atomic variable per consumer I guess in practice it is the same thing (if not and it is just a shared counter, then consumers will be conflicting with each other).