View Single Post
Posts: 838 | Thanked: 3,384 times | Joined on Mar 2009
#9
Originally Posted by szopin View Post
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.
Not sure is this always easy as this:
Code:
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);
 }
This can be dangerous. As you see there are some kind of homemade threading and now bultin __sync_-functions are not used.

This is my reference: http://gcc.gnu.org/onlinedocs/gcc-4....-Builtins.html

And there are (were? it is about gcc4.1.2)
At present GCC ignores this list and protects all variables which are globally accessible.
 

The Following User Says Thank You to AapoRantalainen For This Useful Post: