Hacker News new | ask | show | jobs
by tlb 1388 days ago
std::shared_ptr doesn't use mutexes in any implementation I know of. They use atomic instructions for incrementing and decrementing the reference count, which are very fast.
2 comments

Plus their thread-safety is limited to the pointer's control block not the actual object it's pointing to.

e: nvm reading hard brain mutex too slow

You're right, an atomic inc/dec would also do just fine. I stand corrected.