|
Boost : |
Subject: Re: [boost] storing intrusive_ptr in atomic?!
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2013-10-25 07:04:34
On Fri, Oct 25, 2013 at 11:48 AM, Oliver Kowalke
<oliver.kowalke_at_[hidden]>wrote:
> 2013/10/25 Giovanni Piero Deretta <gpderetta_at_[hidden]>
>
> I'm referring to standard doc at
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf
> Section 3.9. Types -> the example code works for intrusive_ptr too.
>
Well, no, the point is that it won't:
char buf[N];
T obj;
std::memcpy(buf, &obj, N);
std::memcpy(&obj, buf, N);
For T = boost::intrusive_ptr<T2>, the above code formally leads to UB, as
intrusive_ptr is not trivially copiable.
It might (or not) work in practice, but in the case of std::atomic, it will
bypass the copy constructor which means that the reference count won't be
updated.
-- gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk