__atomic_add support without gthreads

Ian Lance Taylor iant@google.com
Mon Feb 23 19:46:00 GMT 2009


"DARIN JOHNSON" <darin@usa.net> writes:

> I noticed some support was in for using atomic operations in
> some C++ library functions in GCC 4.2.  However when looking
> through the code it seems as if some case is being left out.
> The code seems to assume either __GTHREADS is being used, or
> the application is purely single-threaded.  There's no third
> choice where __atomic_add_dispatch() does an atomic add even
> if GTHREADS is not used.  I want to avoid creating a gthreads
> wrapper for our OS.
>
> Am I missing something here?

I'm not sure, but perhaps what you are missing is that if you want to
compile a library with multi-threaded support, you need to provide a
gthreads wrapper.  It doesn't make sense to use atomic operations for
some things but not for, e.g., constructors for static function
variables.

Alternatively, if you just want to write code which uses atomic
operations, but you don't need the library to have multi-threaded
support, then use the builtin __sync_XXX functions, not
__atomic_add_dispatch and friends.

Ian



More information about the Libstdc++ mailing list