UPDATED: Is there a thread-safe, lock-free and available on all Linux distros increment function available in C or C++ ?
+3
A:
The current C and C++ standards don't define such a thing. Your implementation may well have one.
David Seiler
2009-11-08 00:54:44
+5
A:
I think these are GNU extensions, and processor specific, but have a look at GNU C Atomic Builtins.
I think there are also atomic "libraries" available that use inline assembly etc. to provide such features.
Artelius
2009-11-08 00:54:51
+5
A:
GLib has functions to do this. You might check out http://library.gnome.org/devel/glib/stable/glib-Atomic-Operations.html
Specifically, it sounds like you want g_atomic_int_inc()
jstedfast
2009-11-08 01:02:12
Would I need to include GLib as a dependency to my project? Or is this just a .lib ?
jldupont
2009-11-08 01:05:52
Yes, you would need to link to glib, but that shouldn't be a problem since it is available by default on every(?) Linux distro out there.
jstedfast
2009-11-08 01:15:16
It's only available on systems with GNOME installed.
HalfBrian
2009-11-08 01:43:58
While technically GLib is used in GTK+ programs, and typically GTK+ programs run on GNOME, most Linux distributions I'd expect would have a copy of GLib as GTK+ programs are just so prevalent on Linux. Failing which, it's easy enough to download via the distro's package manager
blwy10
2009-11-08 02:21:10