basic_string atomicity

Jonathan Wakely jwakely.gcc@gmail.com
Thu Jan 5 20:01:00 GMT 2012


On 5 January 2012 19:45, David Edelsohn wrote:
> Libstdc++ basic_string ultimately uses the GCC builtin
> __sync_fetch_and_add for atomicity:
>
> #include <ext/atomicity.h>
>            __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
>
> The GTHREAD path in atomicity.h is:
>
>  __atomic_add_dispatch(_Atomic_word* __mem, int __val)
>  {
>      __atomic_add(__mem, __val);
>  }
>
>  static inline void
>  __atomic_add(volatile _Atomic_word* __mem, int __val)
>  { __sync_fetch_and_add(__mem, __val); }
>
> With the addition of C++11 memory model, this builtin now performs
> heavy-weight, full barrier SEQUENTIAL CONSISTENCY semantics.

I thought the __sync builtins were always full barriers too?

> What memory model is required?  It seems like the context for the code
> expects something closer to ACQUIRE semantics.
>
> I opened a GCC Bugzilla about the change in __sync_fetch_and_xxx
> semantics, but it appears that libstdc++ internally should use the new
> __atomic_fetch_add() builtin with more precise semantic intentions.

Yes, eventually.  Similarly for shared_ptr.



More information about the Libstdc++ mailing list