Comparing a std::atomic_flag
to an std::atomic_bool
, it seems to me that a std::atomic_flag
just has a simpler interface. It provides only testing+setting and clearing the flag while an std::atomic_bool
also provides overloads to several operators.
One question of mine is about terminology: What is meant by "load or store operations"? Does it mean that it is not possible to arbitrarily read and modify a std::atomic_flag
's value?
Furthermore, I am wondering, could a std::atomic_bool
be faster when being used for a spin-lock? It seems to me that an std::atomic_flag
always must read AND write during a spin-lock:
while (my_atomic_flag.test_and_set()); // spin-lock
while an std::atomic_bool
would only have to perform a read operation (assuming that the atomic bool is implemented lock-free):
while (my_atomic_bool); // spin-lock
Is an std::atomic_flag
strictly more efficient than an std::atomic_bool
or could it also be the other way round? What should be used for a spin-lock?
Aucun commentaire:
Enregistrer un commentaire