Looking at std::atomic, and by default I read:
These specializations have a standard layout, trivial default constructors, and trivial destructors.
I also read for is_lock_free:
All atomic types, except std::atomic_flag, can be implemented using mutexes or other blocking operations, instead of using blocking instructions on the atomic processor. Automatic types are also allowed sometimes without blocking, for example. if only consistent memory accesses are naturally atomic on a given architecture, displaced objects of the same type should use locks.
Now here is the catch that I am not getting:
How can any type atomicwhere the Standard requires the trivial ctor / dtor to ever use a mutex - all the mutexes I have ever encountered require non-trivial initialization.
This leads to the following questions:
- Do the main platforms provide any blocking operation (for example, a mutex) that is not initialized for each object. (These would be “other blocking operations.”)
- Is there any known implementation today by default for
std::atomicspecializations that are not blocked (and still fulfill the trivial ctor / dtor requirement)? - Am I just confusing something ?:-)
It seems to me that even the simplest spin lock (see atomic_flag) requires non-trivial initialization, so I don’t see how this can be implemented.
: , , .