atomic operations for shared_ptr ?

Marc Glisse marc.glisse@inria.fr
Mon Aug 26 11:41:00 GMT 2013


On Mon, 26 Aug 2013, Florian Weimer wrote:

> On 08/26/2013 01:04 PM, Marc Glisse wrote:
>> On Mon, 26 Aug 2013, Florian Weimer wrote:
>> 
>>> On 08/25/2013 01:52 PM, Oleg Endo wrote:
>>> 
>>>> Just for my understanding, on targets that use 32 bit pointers and have
>>>> a 64 bit atomic (compare and) exchange, that would be a no-brainer,
>>>> wouldn't it?
>>> 
>>> Unfortunately, no.  At least i686 requires 8-byte alignment for the
>>> pair, while we currently only provide 4-byte alignment.  Similarly for
>>> x86_64, where it's 16-byte alignment vs 8-byte.
>> 
>> If changing the alignment in the library would help, please make sure
>> there is a PR open with the ABI keyword. There may be some form of ABI
>> change in 4.10, though I don't know if it will be large enough to allow
>> this...
>
> I'm not sure if we can actually reliably allocate objects with 16 byte 
> alignment on the heap (for x86_64, that is).  If not, achieving this 
> alignment would be rather invasive.

On x86_64, 16 bytes is the alignment used by malloc (on all OS I know of), 
so it should work. I believe it is only over-aligned types that we can't 
handle, like SSE (16) on x86 or AVX (32) on x86_64.

>> (I hate binary compatibility taken too far)
>
> This seems to require pretty far-reaching layout changes, and shared_ptr has 
> been around as std::tr1::shared_ptr for a long time.

We don't have the same expectations wrt binary compatibility, that's ok.

-- 
Marc Glisse



More information about the Libstdc++ mailing list