Why don't std::atomic<integral> specializations provide multiplication and division assignment operators?
-
25-05-2021 - |
Question
The full specializations of std::atomic for integral types provide arithmetic compound assignment operators such as +=
, -=
, but no *=
or /=
. The standard states this but as far as I can see there is no reason given. Could someone familiar with the reasoning behind the Atomic Operations Library section shed some light on this?
Solution
I think this is related to hardware. Many platforms have atomics to handle +=
but I don't know of any that offers *=
. Implementing this through locking would be simple, but the interface of std::atomic
would be mixing at the same level operations that are somehow cheap with very expensive operations.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow