Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to atomically reset a shared_ptr?

We have atomic access to shared_ptrs but I cannot see how to atomically reset them: what am I missing?

like image 686
user1832484 Avatar asked Feb 17 '26 01:02

user1832484


1 Answers

You can just use atomic_exchange with a default constructed shared_ptr:

atomic_exchange(&ptr, {});
like image 86
StoryTeller - Unslander Monica Avatar answered Feb 18 '26 14:02

StoryTeller - Unslander Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!