I'm implementing a pointer / weak pointer mechanism using std::atomic
s for the reference counter (like this). For converting a weak pointer to a strong one I need to atomically
- check if the strong reference counter is nonzero
- if so, increment it
- know whether something has changed.
Is there a way to do this using std::atomic_int
? I think it has to be possible using one of the compare_exchange
, but I can't figure it out.