Please do share your 4.2 fix. This <4.3 bug in gcc is really pretty common/annoying and my googlefu failed me when looking for a solution. I had to switch to 4.4.
src/thread.c @@ -70,5 +70,10 @@ inline s32 testandset(s32 *addr, s32 val) { - return __sync_lock_test_and_set(addr, val); + int return_value = *addr; + *addr=val; + return return_value; + + //It writes value into *ptr, and returns the previous contents of *ptr. + //return __sync_lock_test_and_set(addr, val); } @@ -76,5 +81,10 @@ inline s32 testandadd(s32 *addr, s32 val) { - return __sync_fetch_and_add(addr, val); + int return_value = *addr; + *addr+=val; + return return_value; + + //These builtins perform the operation suggested by the name, and returns the value that had previously been in memory. + //return __sync_fetch_and_add(addr, val); }
At present GCC ignores this list and protects all variables which are globally accessible.