Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error in cplusplus.com atomics op=

25 views
Skip to first unread message

K. Frank

unread,
Nov 16, 2016, 12:19:54 PM11/16/16
to
Hello Group!

The standard states -- 29.6.5-32 -- that for a std::atomic
type, "C A::operator op=(M operand);"

Returns: fetch_key(operand) op operand

That is, the return value is, as one would expect, the
result of performing the operation.

(I am looking at the N3242 draft standard, pg. 1127.)

cplusplus.com has in their atomics reference section:

http://www.cplusplus.com/reference/atomic/atomic/operatororequal/

Each of this functions accesses the contained value, apply
the proper operator and return the value the contained value
had immediately before the operation

and

Return value
The contained value before the call.

So, they have it backwards (as if they were describing
post-increment, rather than pre-increment semantics).


Happy Hacking!


K. Frank

Marcel Mueller

unread,
Nov 17, 2016, 4:39:22 AM11/17/16
to
On 16.11.16 18.19, K. Frank wrote:
> The standard states -- 29.6.5-32 -- that for a std::atomic
> type, "C A::operator op=(M operand);"
>
> Returns: fetch_key(operand) op operand
>
> That is, the return value is, as one would expect, the
> result of performing the operation.
>
> (I am looking at the N3242 draft standard, pg. 1127.)
>
> Return value
> The contained value before the call.
>
> So, they have it backwards (as if they were describing
> post-increment, rather than pre-increment semantics).

Hmm, at least returning the function argument of an assignment makes
less sense within the context of atomics. Any non reversible operation
(like assignment) usually needs access to the previous value in lock
free algorithms.
Maybe from the time before C++11 where exchange() did not exist,
and this is the reason why it is called a draft. ;-)


Marcel
0 new messages