[Gllug] Programming: Atomic Increment/Decrement

Nix nix at esperi.demon.co.uk
Wed Aug 7 22:35:33 UTC 2002


On Wed, 7 Aug 2002, Jonathan Dye uttered the following:
> Does anyone know if there are atomic increment/decrement functions under
> linux (or POSIX)?

Not in POSIX, but if you don't care about nonportability libstdc++-v3
(in GCC 3+) includes some.

See /usr/include/g++-v3/{host-prefix}/bits/atomicity.h:

static void
__attribute__ ((__unused__))
__atomic_add (volatile _Atomic_word* __mem, int __val);

basic_string<> and ios_base<> both use these functions, so in g++, if
either of those are in scope, __atomic_add() will be too.

(Of course, the functions may be stubbed on some architectures and
because they're internal functions they might change underneath you ;)
but you could probably nick the code for different architectures
from the libstdc++ source tree ;} )

-- 
`There's something satisfying about killing JWZ over and over again.'
                                        -- 1i, personal communication

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list