basic_string atomicity

Marc Glisse marc.glisse@inria.fr
Fri Jan 6 09:36:00 GMT 2012


On Thu, 5 Jan 2012, Jonathan Wakely wrote:

> On 5 January 2012 21:28, Jonathan Wakely wrote:
>>>
>>> What consistency model does libstdc++ require?  __sync_fetch_and_xxx
>>> has become more heavy-weight and even the earlier memory model
>>> probably was unnecessarily expensive for its usage in libstdc++ based
>>> on our analysis for POWER.
>>
>> std::string is required by C++11 to be not reference-counted, so
>> changing the details of the ref-counted implementation isn't a high
>> priority if we're going to replace it anyway (although we will retain
>> a ref-counted COW string as __gnu_cxx::__rc_string.)
>>
>> I'm not sure what the memory ordering requirements are for
>> std::string, I think decrementing the count to zero needs to
>> synchronise with deallocating the memory, but I'm not sure about
>> increments.
>
> I think decrementing the refcount in _M_dispose() should be acq_rel,
> but as you suggested the increment in _M_ref_copy only needs to be
> acquire. I think.  Check that with an expert though, I'm not
> confident!

Last time I tried asking experts about something related, it gave:
https://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/cf19ee1e9d4086b9

Not sure it helps (and the exact requirements may differ).

-- 
Marc Glisse



More information about the Libstdc++ mailing list