Subject: Re: [boost] storing intrusive_ptr in atomic?!
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2013-10-25 05:08:42
On Fri, Oct 25, 2013 at 9:11 AM, Oliver Kowalke <oliver.kowalke_at_[hidden]>wrote:
> 2013/10/25 Andrey Semashev <andrey.semashev_at_[hidden]>
> > intrusive_ptr is not trivial-copyable, precisely because it has to
> > on
> > the counter. Using memcpy for copying it is not correct.
> For this reason it is
> > not compatible with atomic<>. You have to use raw pointers with atomic<>.
> I don't agree because the standard told us:
> 1.) 'For any object of trivially copyable type T, whether or not the
> holds a valid value of type T, the underlying bytes making up the object
> can be copied into an array
> of char or unsigned char. If the content of the array of char or unsigned
> char is copied back into the
> object, the object shall subsequently hold its original value.'
> 2.) 'For any trivially copyable type T, if two pointers to T point to
> distinct T objects obj1 and obj2, where
> neither obj1 nor obj2 is a base-class subobject, if the underlying bytes
> (1.7) making up obj1 are copied
> into obj2,41 obj2 shall subsequently hold the same value as obj1.'
Intrusive_ptr doesn't have tivial copy constructor (how could it have? it
needs to update the counter), ergo is not trivially copyable and the above
two point do not apply.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk