This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
basic_string atomicity
- From: David Edelsohn <dje dot gcc at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 5 Jan 2012 14:45:20 -0500
- Subject: 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