Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non thread-safe shared_ptr #59

Open
onqtam opened this issue Mar 27, 2016 · 2 comments
Open

non thread-safe shared_ptr #59

onqtam opened this issue Mar 27, 2016 · 2 comments

Comments

@onqtam
Copy link

onqtam commented Mar 27, 2016

Is there a chance to have a non thread-safe shared_ptr in the standard?

I was thinking either as a new template or maybe the current shared_ptr should have a template parameter if it's ref counting should be atomic.

There is quite a bit of interest in such a thing - see here

Andrei Alexandrescu talked at the cppcon how to implement such a pointer yourself but I feel the standard should provide one - see here

If facebook are doing it - it must be valuable.

Currently the only publicly available solution seems to be building boost with a flag/define to disable thread-safe reference counting.

It might be also good to have the optimizations that Andrei talks about - for the common case when the ref count only goes to 1 and then to 0.

I've already asked this in the google groups for the c++ standard/discussions and I was told that I should make a proposal but I'm not gonna go that route myself just yet.

@jbcoe
Copy link

jbcoe commented Jan 21, 2017

I wonder if this could be done by implementers with the existing shared pointer?

In very simple cases the compiler can deduce that reference count need not be atomic.

@ilyapopov
Copy link

ilyapopov commented May 2, 2018

I wonder if this could be done by implementers with the existing shared pointer?

AFAIK, libstdc++ switches to non-atomic implementation if compiled without -pthread flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants