http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50583
--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 2011-09-30 16:57:14 UTC --- We have 2 choices: 1. Update document of `TYPE __sync_fetch_and_add (TYPE *ptr, TYPE value, ...)' `TYPE __sync_fetch_and_sub (TYPE *ptr, TYPE value, ...)' `TYPE __sync_fetch_and_or (TYPE *ptr, TYPE value, ...)' `TYPE __sync_fetch_and_and (TYPE *ptr, TYPE value, ...)' `TYPE __sync_fetch_and_xor (TYPE *ptr, TYPE value, ...)' `TYPE __sync_fetch_and_nand (TYPE *ptr, TYPE value, ...)' to { tmp = *ptr; tmp1 = tmp OP value; return __sync_val_compare_and_swap (ptr, tmp, tmp1); } 2. Remove those __sync_fetch_and_XXX which aren't { tmp = *ptr; *ptr OP= value; return tmp; } Since only { tmp = *ptr; *ptr OP= value; return tmp; } can be used to implement locks, I think we should do 2.