The C ++ Standard Library has free and member functions for atomic comparison and swap operations.
As indicated by the free features :
These functions are defined in terms of the std :: atomic member functions:obj-> compare_exchange_weak (* expected, desired)obj-> compare_exchange_strong (* expected, desirable)obj-> compare_exchange_weak (* expected, desired, succ, fail)obj-> compare_exchange_strong (* expected, desired, succ, fail)
These functions are defined in terms of the std :: atomic member functions:
What is the reason for having free features? Wouldn't it be enough to have only member functions? Don't they do the same?
Consistency with C operations stdatomic.h.
stdatomic.h
If you use free functions, then the same atom control code will work both in C and C ++, and only for typedef a conditional definition is required.