We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
When executing this code on cortex M3
#include <stdatomic.h> void atomic_swap () { _Atomic int a = 5; int b = 5; if ( true == atomic_compare_exchange_strong ( & a, & b, 5) ) __breakpoint ( 2 ); // this is never reached }
why atomic_compare_exchange_strong () does not return true and hit the __breakpoint () ?
'a' and 'b' are equal so according to https://en.cppreference.com/w/c/atomic/atomic_compare_exchange 'true' should be returned.
Thanks
If the program hits the breakpoint, atomic_compare_exchange_strong() did return "true" according to your code snippet. You are checking for "true == true" in this case which makes the if-statement become true.
"If the program hits the breakpoint" - it does not.