Get the latest tech news
Shared_ptr<T>: the (not always) atomic reference counted smart pointer (2019)
Introduction This is a write-up of the “behavioral analysis” of shared_ptr<T> reference count in GNU’s libstdc++. This smart pointer is used to share references to the same underlaying pointer.
Inside KCachegrind, I saw something unexpected, the code was straightforward but before increasing shared_ptr ’s reference count during a pointer copy, there was a branch to decide if it should do an atomic addition or a non-atomic one. I assume that this is also a very rare case and from a quick googling, I can see tons of problems caused by using dlopen in statically compiled binaries. While I’m probably not going to spend any more time on this, I’ve found a personally unknown thing about C++ standard library (GNU) and wanted to document it because it was interesting to track down.
Or read this on Hacker News