Consider this code snippet:
static std::atomic<bool> var; //the variable to update.
// Update() updates the variable `var`
void Update() {
bool result = Foo(); //Foo() is some function returning a boolean.
// The doubt is here in this conditional store.
if (result != var) {
var = result;
}
}
If Update() is called frequently, say multiple threads, one wouldn't want to store result to var if already var == result due to cache failures.
The question follows:
-
Does
if (result != var) var = resultget optimized tovar = result? -
Does this optimization (if any) differ if var is not an atomic?
Aucun commentaire:
Enregistrer un commentaire