Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does std::atomic's compare_exchange take a reference for the expected value?

Tags:

c++

c++11

atomic

What is the reason for std::atomic<T>::compare_exchange_* taking the expected value by reference, instead of taking it by value?

like image 528
Collin Dauphinee Avatar asked Nov 14 '13 19:11

Collin Dauphinee


1 Answers

compare_exchange_* changes expected to actual value if operation fails. It makes loops a bit simpler.

like image 67
zch Avatar answered Nov 08 '22 17:11

zch