Hi,
I've noticed behaviour which doesn't match that described in the GCC
manual for the __sync_bool_compare_and_swap builtin, when operating on
objects of type 'bool'.
Take the following test program as an example, tested on a PowerPC ibook
with GCC 4.3.0:
int main(int argc, char **argv)
{
bool a = true;
// Swap the value 'true' with 'false' and return true on success.
bool b = __sync_bool_compare_and_swap(&a, true, false);
return (b) 2 : 1;
}
This returns '1' - that is, the compare and swap failed - even there is
no reason for it to fail. Interesting to note is that this behaviour is
/not/ exhibited on x86, x86_64 or mips32 (the only other platforms I was
able to test on), and neither is it exhibited if swapping false with
true, for example:
int main(int argc, char **argv)
{
bool a = false;
// Swap the value 'false' with 'true' and return true on success.
bool b = __sync_bool_compare_and_swap(&a, false, true);
return (b) 2 : 1;
}
The above program returns '2'.
I'd be interested in any response - Am I right in saying that this is
unintended behaviour or am I somehow using the function outside its
intended remit?
Cheers,
James Molloy