[libdispatch-dev] lib dispatch worker threads may loop depending on compiler optimization

Dmitri Shubin sbn at tbricks.com
Fri Sep 9 00:27:05 PDT 2011

On 09.09.2011 11:23, Dave Zarzycki wrote:
> In practice, GCC and clang have historically treated 
> _sync_lock_test_and_set() as a full barrier, and that is why GCD was 
> able to get away with using it to get at the "xchg" instruction.
> The behavior of _sync_lock_test_and_set() may have changed in recent GCC compilers, and this would explain the bug observed in this email thread where the store instruction was statically moved after the "xchg" instruction. That is why the recently introduced __sync_swap() intrinsic is preferable when available.

If you need full barrier why not explicitly call |__sync_synchronize()| 
before |__sync_lock_test_and_set() in dispatch_atomic_xchg() then?|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-dev/attachments/20110909/b4c5ea05/attachment.html>

More information about the libdispatch-dev mailing list