This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Question on GCC 4.8 atomics
- From: Andrew Haley <aph at redhat dot com>
- To: Bjorn Lindgren <nr at c64 dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 05 Apr 2013 13:38:45 +0100
- Subject: Re: Question on GCC 4.8 atomics
- References: <Pine dot LNX dot 4 dot 62 dot 1304051331100 dot 2044 at localhost dot localdomain> <515EBC8D dot 1080402 at redhat dot com> <Pine dot LNX dot 4 dot 62 dot 1304051412160 dot 2044 at localhost dot localdomain>
On 04/05/2013 01:33 PM, Bjorn Lindgren wrote:
>
> On Fri, 5 Apr 2013, Andrew Haley wrote:
>
>> On 04/05/2013 12:39 PM, Bjorn Lindgren wrote:
>>> I would like to know if the built-in __atomic_* function calls are always
>>> garanteed to succeed? If for example multiple threads on different
>>> sockets/cores call the __atomic function on a globaly shared variable at
>>> same time, are the calls then queued and executed?
>>
>> I can't tell exactly what this question means. I think you're asking if,
>> for example, an atomic_fetch-and-modify might fail to modify its target.
>> The answer is no: while the cmpxchg fails it will retry.
>
> Well, that was what I wanted to find out, do I need error handling if the
> event of a colliction (two cores exectuing CMPXCHG within the same clock
> cycles), the instruction will be automaticly retried until it succeeds?
Correct.
> Is that true for the x86 asm implementations of __atomic_*_fetch /
> __atomic_fetch_* calls too, that they are retried?
Which x86 asm implementations do you mean? We're talking about
GCC here, and it has builtins.
> As I understand each core has it's own context and instruction
> pipeline so a __atomic function call collision could
> occur across cores.
Indeed it could, but this is all too vague for me. Some builtins can
fail, some can't. Those that can fail indicate failure with a status code.
Andrew.