Topic: Semantics of some std::atomic<iType> member functions


Author: Scott Meyers <usenet@aristeia.com>
Date: Tue, 3 Nov 2009 12:07:46 CST
Raw View
29.5.1 in N2960 declares the following member functions for std::atomic_itype:

integral operator+=(integral) volatile;
integral operator-=(integral) volatile;
integral operator&=(integral) volatile;
integral operator|=(integral) volatile;
integral operator^=(integral) volatile;

Some of these are also declared for std::atomic_address and std::atomic<T*>.
But I can't find any description of their semantics including, rather
critically, whether they are atomic operations.  Am I overlooking semantic
descriptions somewhere?

Thanks,

Scott

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Pete Becker <pete@versatilecoding.com>
Date: Tue, 3 Nov 2009 17:08:18 CST
Raw View
Scott Meyers wrote:
> 29.5.1 in N2960 declares the following member functions for
> std::atomic_itype:
>
> integral operator+=(integral) volatile;
> integral operator-=(integral) volatile;
> integral operator&=(integral) volatile;
> integral operator|=(integral) volatile;
> integral operator^=(integral) volatile;
>
> Some of these are also declared for std::atomic_address and
> std::atomic<T*>.
> But I can't find any description of their semantics including, rather
> critically, whether they are atomic operations.  Am I overlooking semantic
> descriptions somewhere?
>

[atomics.types.operations]/26

--
    Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Tue, 3 Nov 2009 17:10:40 CST
Raw View
Scott Meyers <usenet@aristeia.com> writes:

> 29.5.1 in N2960 declares the following member functions for
> std::atomic_itype:
>
> integral operator+=(integral) volatile;
> integral operator-=(integral) volatile;
> integral operator&=(integral) volatile;
> integral operator|=(integral) volatile;
> integral operator^=(integral) volatile;
>
> Some of these are also declared for std::atomic_address and std::atomic<T*>.
> But I can't find any description of their semantics including, rather
> critically, whether they are atomic operations.  Am I overlooking semantic
> descriptions somewhere?

See 29.6p6.

C A::operator op=(M operand) volatile;
E   ?ects: fetch_key(operand)
Returns: fetch_key(operand) op operand

where "key" and "op" are given in table 137. This says that a+=b
is equivalent to a.fetch_add(b)+b, and so forth for the other operators.

Anthony
--
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Just Software Solutions Ltd         | http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Scott Meyers <usenet@aristeia.com>
Date: Fri, 6 Nov 2009 14:43:39 CST
Raw View
Anthony Williams wrote:
>
> See 29.6p6.
>
> C A::operator op=(M operand) volatile;
> Effects: fetch_key(operand)
> Returns: fetch_key(operand) op operand
>
> where "key" and "op" are given in table 137. This says that a+=b
> is equivalent to a.fetch_add(b)+b, and so forth for the other operators.

Okay, I see it now.  Silly me, searching for "|=" in an attempt to
find a description of semantics for operator|=.

For the record, my copy of N2960 has this information in paragraphs
22ff, not paragraph 6.

Scott


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Sat, 7 Nov 2009 18:05:27 CST
Raw View
Scott Meyers <usenet@aristeia.com> writes:

> Anthony Williams wrote:
>>
>> See 29.6p6.
>>
>> C A::operator op=(M operand) volatile;
>> Effects: fetch_key(operand)
>> Returns: fetch_key(operand) op operand
>>
>> where "key" and "op" are given in table 137. This says that a+=b
>> is equivalent to a.fetch_add(b)+b, and so forth for the other operators.
>
> Okay, I see it now.  Silly me, searching for "|=" in an attempt to
> find a description of semantics for operator|=.

:-)

> For the record, my copy of N2960 has this information in paragraphs
> 22ff, not paragraph 6.

Oops, that was a typo. I meant paragraph 26 (which is what I quoted
above), but yes everything from 22 onwards is relevant.

Anthony
--
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Just Software Solutions Ltd         | http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]