?
camper schrieb:
In jedem Fall sehe ich nicht, was triviale Kopierbarkeit im Zusammenhang mit atomics bringen soll.
std::atomic verlangt, dass der verwaltete Typ trivially copyable ist (29.5 (1)).
Allerdings ist das, wo ich nochmal drüber nachdenke und n2427 etwas genauer lese, vermutlich nicht das, worum es hier geht (mea culpa). Dieser Absatz lässt mich vermuten, dass es um die Regel der Fünf geht:
We also provide the common fetch-and-modify operations. The fetch-and-modify functions return the original stored value. The original stored value is required for fetch-and-or and fetch-and-and because there is no means to compute to the original stored value from the new value and the modifying argument. In contrast to the functions, the fetch-and-modify assignment operators return the new value. We do this for consistency with normal assignment operators. Unlike normal C++ assignment operators, though, the atomic assignments return values rather than references, which is like C. The reason is that another thread might intervene between an assignment and a subsequent read. Rather than introduce this classic parallel programming bug, we return a value.
Aus diesem Grund gibt es keine normalen Zuweisungsoperatoren, und ohne Zuweisungsoperatoren sind Kopier- respektive Move-Konstruktoren eine gefährliche Idee.
Man könnte darüber nachdenken, ob std::atomic Zuweisungsoperatoren anbieten könnte, die einen std::atomic by-value zurückgeben (wofür man dann einen Kopierkonstruktor bräuchte), aber die Verwendung des Rückgabetyps wäre wohl eine ziemlich verwirrende Angelegenheit.