[Patch] Use __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*

Peter Dimov pdimov@mmltd.net
Mon May 28 13:01:00 GMT 2007


Paolo Carlini wrote:
> Peter Dimov wrote:
>
>> Benjamin Kosnik wrote:
>>
>>>> 2007-05-24  Paolo Carlini  <pcarlini@suse.de>
>>>>
>>>> * include/ext/concurrence.h: Use
>>>> __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*.
>>>
>>> Excellent news indeed.
>>
>> The macros seem pretty useful. Are they going to be in 4.3? I'm
>> converting some boost::shared_ptr code to use __sync_* and running
>> into the i386 'unresolved __sync_..._4' problem. What is the usual
>> way to deal with that?
>
> The macros are already in mainline and documented as builtin macros.
> That means will certainly be in 4.3.x.
>
> Well, the *usual* way to deal with that isn't really satisfactory, and
> that't why I (we) decided to add the macros: the availability of the
> atomic builtins depends on the actual -march etc switches and a
> "static" autoconf test is always too conservative for such arches.

I see that your current approach is to use a mutex when the macro reports 
unavailability.

There is an alternative; supply the __sync_..._{1,2,4,8} functions (as weak 
symbols maybe?) for i386 and similar targets, implemented with a spinlock 
pool, as suggested in N2145. This will have the advantage of making user 
code "just work". One downside would be that some users may not realize that 
they're getting an emulation.

FWIW, in Boost for x86 I silently assume 486 and above and switch to a 
separate inline assembly implementation, bypassing __sync_*. 



More information about the Libstdc++ mailing list