Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't std::atomic<integral> specializations provide multiplication and division assignment operators?

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?

like image 747
juanchopanza Avatar asked Mar 22 '12 15:03

juanchopanza


1 Answers

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.

like image 126
David Rodríguez - dribeas Avatar answered Oct 21 '22 05:10

David Rodríguez - dribeas