Topic: Can we get a shared_ptr with non thread-safe
Author: Viktor Kirilov <vik.kirilov@gmail.com>
Date: Fri, 17 Apr 2015 01:39:50 -0700 (PDT)
Raw View
------=_Part_386_2022144593.1429259990523
Content-Type: multipart/alternative;
boundary="----=_Part_387_107977129.1429259990523"
------=_Part_387_107977129.1429259990523
Content-Type: text/plain; charset=UTF-8
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.
This shouldn't be hard to implement - its a simpler case for the current
shared_ptr.
There is interest in such a thing -
http://stackoverflow.com/questions/6593770/creating-a-non-thread-safe-shared-ptr
Andrei Alexandrescu talked at the cppcon how to implement such a pointer
yourself ( https://www.youtube.com/watch?v=Qq_WaiwzOtI ) but I think the
standard should provide one.
Currently the only publicly available solution seems to be building boost
with a flag/define to disable thread-safe reference counting (according to
that StackOverflow question).
I posted this first in [std-discussion] but maybe it belongs here.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_387_107977129.1429259990523
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Is there a chance to have a non thread-safe shared_pt=
r in the standard?</div><div><br></div><div>I was thinking either as a new =
template or maybe the current shared_ptr should have a template parameter i=
f it's ref counting should be atomic.</div><div><br></div><div>This shouldn=
't be hard to implement - its a simpler case for the current shared_ptr.</d=
iv><div><br></div><div>There is interest in such a thing - http://stackover=
flow.com/questions/6593770/creating-a-non-thread-safe-shared-ptr</div><div>=
<br></div><div>Andrei Alexandrescu talked at the cppcon how to implement su=
ch a pointer yourself ( https://www.youtube.com/watch?v=3DQq_WaiwzOtI ) but=
I think the standard should provide one.</div><div><br></div><div>Currentl=
y the only publicly available solution seems to be building boost with a fl=
ag/define to disable thread-safe reference counting (according to that Stac=
kOverflow question).</div><div><br></div><div>I posted this first in [std-d=
iscussion] but maybe it belongs here.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_387_107977129.1429259990523--
------=_Part_386_2022144593.1429259990523--
.
Author: "Nadav Har'El" <nyh@cloudius-systems.com>
Date: Sun, 19 Apr 2015 13:30:42 +0300
Raw View
--001a1133a85c38f4ee0514114ed1
Content-Type: text/plain; charset=UTF-8
On Fri, Apr 17, 2015 at 11:39 AM, Viktor Kirilov <vik.kirilov@gmail.com>
wrote:
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.
>
> This shouldn't be hard to implement - its a simpler case for the current
> shared_ptr.
>
> There is interest in such a thing -
> http://stackoverflow.com/questions/6593770/creating-a-non-thread-safe-shared-ptr
>
> Andrei Alexandrescu talked at the cppcon how to implement such a pointer
> yourself ( https://www.youtube.com/watch?v=Qq_WaiwzOtI ) but I think the
> standard should provide one.
>
> Currently the only publicly available solution seems to be building boost
> with a flag/define to disable thread-safe reference counting (according to
> that StackOverflow question).
>
Another project where non-thread-safe shared_ptr was desired - and
implemented - is the Seastar project (http://www.seastar-project.org/).
Seastar is an open-source C++14 library for building high-performance
server applications.
For optimum performance on many-core machines, Seastar applications use the
share-nothing approach (different cores work on different data), so shared
pointers are never shared between threads, and thus do not need
thread-safety. The traditional thread-safe reference counting
implementation, using the x86 atomic increment/decrement instructions,
significantly slows down the use of shared pointers - and even worse (as
far as the Seastar project is concerned), ruins its scalability as the
number of cores becomes large (especially on multi-socket setups).
So you can find in Seastar's thread-unsafe implementation of
std::shared_ptr in it's source code (this implementation is
Apache-licensed, so may be reused by almost anyone):
https://github.com/cloudius-systems/seastar/blob/master/core/shared_ptr.hh
Seastar actually implemented two variants - one is shared_ptr, compatible
with the traditional std::shared_ptr (without the thread safety). The
second one is lw_shared_ptr, an even lighter variant which uses smaller
pointers (just one machine pointer) and smaller overhead added to the
shared object - but doesn't permit polymorphism. In many situations, this
lightweight variant is enough, and provides even better performance.
By the way, I'd like to add that in theory, it might be possible to have
our cake and eat it too, i.e., have a reference-counter which is *both*
thread safe and scalable in number of cores. One of the relevant research
papers I've read in the past about how to do this is "SNZI: Scalable
NonZero Indicators". Using this or similar algorithm, one might implement
the existing std::shared_ptr in a scalable way, without giving up on the
thread-safety guarantee. But I'm guessing that while SNZI-like methods will
indeed be more scalable, they might not be any faster on a machine with
only a few cores. These sort of techniques will become very important as
the number of cores on machines continue to increase, and even when we do
need thread-safety, it never needs to involve all cores.
Nadav Har'El.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a1133a85c38f4ee0514114ed1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Apr 17, 2015 at 11:39 AM, Viktor Kirilov <span dir=3D"ltr"><<a href=
=3D"mailto:vik.kirilov@gmail.com" target=3D"_blank">vik.kirilov@gmail.com</=
a>></span> wrote:<br><br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1e=
x"><div dir=3D"ltr"><div>Is there a chance to have a non thread-safe shared=
_ptr in the standard?</div><div><br></div><div>I was thinking either as a n=
ew template or maybe the current shared_ptr should have a template paramete=
r if it's ref counting should be atomic.</div><div><br></div><div>This =
shouldn't be hard to implement - its a simpler case for the current sha=
red_ptr.</div><div><br></div><div>There is interest in such a thing - <a hr=
ef=3D"http://stackoverflow.com/questions/6593770/creating-a-non-thread-safe=
-shared-ptr" target=3D"_blank">http://stackoverflow.com/questions/6593770/c=
reating-a-non-thread-safe-shared-ptr</a></div><div><br></div><div>Andrei Al=
exandrescu talked at the cppcon how to implement such a pointer yourself ( =
<a href=3D"https://www.youtube.com/watch?v=3DQq_WaiwzOtI" target=3D"_blank"=
>https://www.youtube.com/watch?v=3DQq_WaiwzOtI</a> ) but I think the standa=
rd should provide one.</div><div><br></div><div>Currently the only publicly=
available solution seems to be building boost with a flag/define to disabl=
e thread-safe reference counting (according to that StackOverflow question)=
..</div></div></blockquote><div><br></div><div>Another project where non-thr=
ead-safe shared_ptr was desired - and implemented - is the Seastar project =
(<a href=3D"http://www.seastar-project.org/">http://www.seastar-project.org=
/</a>). Seastar is an open-source C++14 library for building high-performan=
ce server applications.<br><br>For optimum performance on many-core machine=
s, Seastar applications use the share-nothing approach (different cores wor=
k on different data), so shared pointers are never shared between threads, =
and thus do not need thread-safety. The traditional thread-safe reference c=
ounting implementation, using the x86 atomic increment/decrement instructio=
ns, significantly slows down the use of shared pointers - and even worse (a=
s far as the Seastar project is concerned), ruins its scalability as the nu=
mber of cores becomes large (especially on multi-socket setups).<br><br></d=
iv><div>So you can find in Seastar's thread-unsafe implementation of st=
d::shared_ptr in it's source code (this implementation is Apache-licens=
ed, so may be reused by almost anyone):<br><br><a href=3D"https://github.co=
m/cloudius-systems/seastar/blob/master/core/shared_ptr.hh">https://github.c=
om/cloudius-systems/seastar/blob/master/core/shared_ptr.hh</a><br><br></div=
><div>Seastar actually implemented two variants - one is shared_ptr, compat=
ible with the traditional std::shared_ptr (without the thread safety). The =
second one is lw_shared_ptr, an even lighter variant which uses smaller poi=
nters (just one machine pointer) and smaller overhead added to the shared o=
bject - but doesn't permit polymorphism. In many situations, this light=
weight variant is enough, and provides even better performance.<br><br></di=
v><div>By the way, I'd like to add that in theory, it might be possible=
to have our cake and eat it too, i.e., have a reference-counter which is *=
both* thread safe and scalable in number of cores. One of the relevant rese=
arch papers I've read in the past about how to do this is "SNZI: S=
calable NonZero Indicators". Using this or similar algorithm, one migh=
t implement the existing std::shared_ptr in a scalable way, without giving =
up on the thread-safety guarantee. But I'm guessing that while SNZI-lik=
e methods will indeed be more scalable, they might not be any faster on a m=
achine with only a few cores. These sort of techniques will become very imp=
ortant as the number of cores on machines continue to increase, and even wh=
en we do need thread-safety, it never needs to involve all cores.<br><br></=
div><div>Nadav Har'El.<br></div></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a1133a85c38f4ee0514114ed1--
.
Author: Viktor Kirilov <vik.kirilov@gmail.com>
Date: Sun, 19 Apr 2015 04:03:28 -0700 (PDT)
Raw View
------=_Part_2199_1186625024.1429441408304
Content-Type: multipart/alternative;
boundary="----=_Part_2200_2073632326.1429441408304"
------=_Part_2200_2073632326.1429441408304
Content-Type: text/plain; charset=UTF-8
I couldn't find weak_ptr functionality within the Seastar project along
with the shared_ptr.
I'm more interested in having this in the standard.
Has anyone ever proposed it?
What chances will it have getting into the standard if it is proposed?
On Friday, April 17, 2015 at 11:39:50 AM UTC+3, Viktor Kirilov wrote:
>
> 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.
>
> This shouldn't be hard to implement - its a simpler case for the current
> shared_ptr.
>
> There is interest in such a thing -
> http://stackoverflow.com/questions/6593770/creating-a-non-thread-safe-shared-ptr
>
> Andrei Alexandrescu talked at the cppcon how to implement such a pointer
> yourself ( https://www.youtube.com/watch?v=Qq_WaiwzOtI ) but I think the
> standard should provide one.
>
> Currently the only publicly available solution seems to be building boost
> with a flag/define to disable thread-safe reference counting (according to
> that StackOverflow question).
>
> I posted this first in [std-discussion] but maybe it belongs here.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2200_2073632326.1429441408304
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I couldn't find weak_ptr functionality within the Sea=
star project along with the shared_ptr.</div><div><br></div><div>I'm more i=
nterested in having this in the standard.</div><div>Has anyone ever propose=
d it?</div><div>What chances will it have getting into the standard if it i=
s proposed?</div><br>On Friday, April 17, 2015 at 11:39:50 AM UTC+3, Viktor=
Kirilov wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><div>Is there a chance to have a non thread-safe shared_ptr in the standa=
rd?</div><div><br></div><div>I was thinking either as a new template or may=
be the current shared_ptr should have a template parameter if it's ref coun=
ting should be atomic.</div><div><br></div><div>This shouldn't be hard to i=
mplement - its a simpler case for the current shared_ptr.</div><div><br></d=
iv><div>There is interest in such a thing - <a href=3D"http://stackoverflow=
..com/questions/6593770/creating-a-non-thread-safe-shared-ptr" target=3D"_bl=
ank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.com/url=
?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F6593770%2Fcreating-a-non-=
thread-safe-shared-ptr\46sa\75D\46sntz\0751\46usg\75AFQjCNEDKoEboAcpYvGJLRR=
JU0yey4Ejww';return true;" onclick=3D"this.href=3D'http://www.google.com/ur=
l?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F6593770%2Fcreating-a-non=
-thread-safe-shared-ptr\46sa\75D\46sntz\0751\46usg\75AFQjCNEDKoEboAcpYvGJLR=
RJU0yey4Ejww';return true;">http://stackoverflow.com/<wbr>questions/6593770=
/creating-a-<wbr>non-thread-safe-shared-ptr</a></div><div><br></div><div>An=
drei Alexandrescu talked at the cppcon how to implement such a pointer your=
self ( <a href=3D"https://www.youtube.com/watch?v=3DQq_WaiwzOtI" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://www.youtube.co=
m/watch?v\75Qq_WaiwzOtI';return true;" onclick=3D"this.href=3D'https://www.=
youtube.com/watch?v\75Qq_WaiwzOtI';return true;">https://www.youtube.com/wa=
tch?<wbr>v=3DQq_WaiwzOtI</a> ) but I think the standard should provide one.=
</div><div><br></div><div>Currently the only publicly available solution se=
ems to be building boost with a flag/define to disable thread-safe referenc=
e counting (according to that StackOverflow question).</div><div><br></div>=
<div>I posted this first in [std-discussion] but maybe it belongs here.</di=
v></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2200_2073632326.1429441408304--
------=_Part_2199_1186625024.1429441408304--
.
Author: "Nadav Har'El" <nyh@cloudius-systems.com>
Date: Sun, 19 Apr 2015 15:55:50 +0300
Raw View
--001a11c33e2e3d24c70514135503
Content-Type: text/plain; charset=UTF-8
On Sun, Apr 19, 2015 at 2:03 PM, Viktor Kirilov <vik.kirilov@gmail.com>
wrote:
> I couldn't find weak_ptr functionality within the Seastar project along
> with the shared_ptr.
>
I think this wasn't needed there, so it was never implemented, but there's
no real reason not to add it.
I'm more interested in having this in the standard.
>
In order to suggest why something should be in a standard, it is usually
good to have evidence that this idea actually works, and is useful in
practice. I suggested that Seastar is an evidence why your idea is indeed
useful (as well as being implementation you can try today).
> Has anyone ever proposed it?
> What chances will it have getting into the standard if it is proposed?
>
I don't know :-) I'm a newbie on this list. Let's wait for more
knowledgeable people to respond.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c33e2e3d24c70514135503
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Apr 19, 2015 at 2:03 PM, Viktor Kirilov <span dir=3D"ltr"><<a href=
=3D"mailto:vik.kirilov@gmail.com" target=3D"_blank">vik.kirilov@gmail.com</=
a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><di=
v>I couldn't find weak_ptr functionality within the Seastar project alo=
ng with the shared_ptr.</div></div></blockquote><div><br></div><div>I think=
this wasn't needed there, so it was never implemented, but there's=
no real reason not to add it.<br><br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr"><div></div><div>I'm more interested in having this in =
the standard.</div></div></blockquote><div><br></div><div>In order to sugge=
st why something should be in a standard, it is usually good to have eviden=
ce that this idea actually works, and is useful in practice. I suggested th=
at Seastar is an evidence why your idea is indeed useful (as well as being =
implementation you can try today).<br>=C2=A0<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div dir=3D"ltr"><div>Has anyone ever proposed it?</div><div>What=
chances will it have getting into the standard if it is proposed?</div></d=
iv></blockquote><div><br></div><div>I don't know :-) I'm a newbie o=
n this list. Let's wait for more knowledgeable people to respond.<br></=
div><br></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c33e2e3d24c70514135503--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 19 Apr 2015 16:03:31 +0300
Raw View
On 19 April 2015 at 14:03, Viktor Kirilov <vik.kirilov@gmail.com> wrote:
> I'm more interested in having this in the standard.
> Has anyone ever proposed it?
Not that I recall. The decision to make shared_ptr thread-safe was
well-considered
and deliberate, but there was no prejudice against a non-thread-safe
one should a
need for such thing arise.
> What chances will it have getting into the standard if it is proposed?
Given a good proposal with decent motivation (which the outline of the Seastar
project and its needs provides to certain extent), it stands a decent
chance. I would not be surprised
by various sorts of conservative opposition. It's hard to predict
which way it will go.
Personally I find it an idea worth proposing.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.