This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
using atomic builtins
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: rth at redhat dot com, phillip dot m dot jordan at gmail dot com
- Date: Mon, 26 Jun 2006 12:58:50 -0500
- Subject: using atomic builtins
Hey all!
I've been reviewing some of the excellent work that Phillip is doing
for summer of code.
As part of that, I'm reviewing:
http://mulliard.homelinux.org/~phillip/code/soc/patches/shared_ptr.patch
However, when I try to build/test with this patch on various i686 flavors, I get:
undefined reference to "__sync_bool_compare_and_swap_4".
So, I find:
http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html#Atomic-Builtins
Specifically:
"If a particular operation cannot be implemented on the target
processor, a warning will be generated and a call an external function
will be generated"
So, that seems to be happening here. Or, some of it. I am only getting
a link-time, undefined function error.
I'm a bit confused: I thought there was supposed to be compile-time
warning? Maybe just wishful thinking?
Here's a bit of sample code:
#include <bits/atomicity.h>
int main()
{
_Atomic_word c1;
_Atomic_word c2;
if (!__sync_bool_compare_and_swap(&c1, c2, c2 + 1))
{
// Do something.
}
return 0;
}
One approach to using the atomic builtins would be to have a compile
error/warning if these atomic builtins could not be used. Then, a
configure test could be crafted to flip a bit on or off if the host
supported such things. Then, using the atomic bits would just be a
matter of configure/build time switching between this and a generic,
non-builtin interface. Seems pretty simple, but of course I'm probably
simplifying too much.
Link time errors are just going to be harder to deal with, although I
suppose it could be done this way too.
Thoughts on usage?
-benjamin