Re: Memory model release/acquire mode interactions of relaxed atomic operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4 May 2017 at 13:56, Toebs Douglass <toby@xxxxxxxxxxxxxx> wrote:
> On 04/05/17 14:40, Andrew Haley wrote:
>> On 04/05/17 13:11, Toebs Douglass wrote:
>
>>> This being true if and only if the atomic load/store functions are used,
>>> right?
>>
>> It works for all accesses: atomicity is part of the type.
>
> Why do the load()/store() functions exist?
>
> Like this, from the OP;
>
>> if (x.load(memory_order_acquire) == 10)
>>   assert (y == 20);
>
> Only to specify the memory model?

Yes, to explicitly specify the memory ordering.

x == 10 is exactly equivalent to x.load(memory_order_seq_cst) == 10.

i.e. the default ordering is SC.

> But if you access the variable without the function, how would the
> compiler know what memory model you wanted to use?

RTFM. http://en.cppreference.com/w/cpp/atomic/atomic/operator_T


> Also, you are then saying that seemingly-unadorned accesses, i.e.
>
> x = 1;
>
> Will cause the compiler to emit not just compiler barriers, but memory
> barriers?  will the compiler in fact convert this into an atomic - in
> the LL/SC sense - operation?  (I don't think this is so?)

x = 1 is exactly equivalent to x.store(memory_order_seq_cst).

http://en.cppreference.com/w/cpp/atomic/atomic/operator%3D



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux