Andrew Haley wrote: > this stuff really should be done by the compiler. Yes. I've filed a bug asking for a __sync_lock_test_and_set builtin: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33413 In the meantime I'm happy with the asm that I posted at the start of this thread. Regards, Phil.