Boost logo

Boost :

From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2007-09-12 17:32:38


Phil Endecott wrote:
> Peter Dimov wrote:
>> Do __sync_lock_test_and_set and __sync_lock_release work?
>
> __sync_lock_test_and_set doesn't work.

> So "test and set" is actually an atomic swap, i.e. exactly what ARM has

> Yet gcc still doesn't seem to implement it. I will go and ask on their
> mailing list.

Here is what I have learnt from gcc-help:

- You can test for the presence of atomic-add and related builtins
using the __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n predefined macros, so this
could be used to enable the sp_counted_base implementation that Peter
has done based on them. Except that this macro is only defined in
relatively recent versions of the compiler, i.e. there are compilers
that have the builtins but don't advertise them with the macro.

- There is no ARM builtin for SWAP; I've filed a gcc bug suggesting it
(and a corresponding macro) as an enhancement.

- The code that I presented, which uses a sentinel value to lock the
count and spins if it finds it already locked, will have problems on a
system where a high-priority thread must explicitly yield to let lower
priority threads run. This isn't the case on any system that I
(currently) care about, but it did make me wonder whether Boost has a
policy on supported threading models, and whether any of the other
Boost atomicity / threading code would suffer the same issue.

Regards,

Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk