This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Clarify __atomic_compare_exchange_n docs


On 10/01/2015 05:28 AM, Andrew Haley wrote:
On 09/29/2015 04:21 PM, Sandra Loosemore wrote:
What is "weak compare_exchange", and what is "the strong variation", and
how do they differ in terms of behavior?

It's in C++11 29.6.5:

Remark: The weak compare-and-exchange operations may fail spuriously,
that is, return false while leaving the contents of memory pointed to
by expected before the operation is the same that same as that of the
object and the same as that of expected after the operation. [ Note:
This spurious failure enables implementation of compare-and-exchange
on a broader class of machines, e.g., load- locked store-conditional
machines. A consequence of spurious failure is that nearly all uses of
weak compare-and-exchange will be in a loop.  When a
compare-and-exchange is in a loop, the weak version will yield better
performance on some platforms. When a weak compare-and-exchange would
require a loop and a strong one would not, the strong one is
preferable. — end note ]

The classic use of this is for shared counters: you don't care if you
miss an occasional count but you don't want the counter to go
backwards.

Whether we should replicate all of the C++11 language is perhaps
something we should discuss.

Hmmmm, yes. Looking at the section as a whole, is it a bug in the implementation that the built-ins only "approximately match" the C++11 requirements? If there were an exact correspondence, it would only be necessary to point at the standard (I think it would be more helpful to mention <stdatomic.h> here than to cite a specific section number), identify what C++11 names the built-ins map onto, and to document any implementation-defined behavior allowed by the standard and GCC extensions.

-Sandra


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]