I am looking for a way in C++ bool type (or possibly C int), that checking (if statement) and editing the bool in a single instruction. Google search got me nowhere, maybe I am using wrong keywords.
Example:
bool valid;
.
.
.
if(valid){
    valid = false;
    // do stuff
}
For now, I use std::atomic<bool>, but still, if(valid) and valid = false are different instructions, and in a multi thread environment, there are things getting in between. Is there a way to make this 2 operations atomic, without using mutexes ?
I am using GCC 11 / G++ 11.
 
    