logoalt Hacker News

accelbredyesterday at 4:49 PM3 repliesview on HN

Unfortunately, for C++, thats not true. At least with glibc and libstdc++, if you do not link with pthreads, then shared pointers are not thread-safe. At runtime it will do a symbol lookup for a pthreads symbol, and based off the result, the shared pointer code will either take the atomic or non-atomic path.

I'd much rather it didnt try to be zero-cost and it always used atomics...


Replies

TuxSHyesterday at 6:42 PM

True, but that's a fault of the implementation, which assumes POSIX is the only thing in town & makes questionable optimization choices, rather that of the language itself

(for reference, the person above is referring to what's described here: https://snf.github.io/2019/02/13/shared-ptr-optimization/)

show 1 reply
woodruffwyesterday at 5:08 PM

This is, impressively, significantly worse than I realized!

eddd-dddeyesterday at 7:11 PM

Why use atomics if you don't need them? There really should just be two different shared pointer types.

show 1 reply