This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

basic_string atomicity


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.

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.

Thanks, David


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]