According to the C++17 standard, [support.signal], the atomic object should satisfy the following requirements to be used in a signal handler:
- [...], or
f
is a non-static member function invoked on an objectA
, such thatA.is_lock_free()
yieldstrue
, orf
is a non-member function, and for every pointer-to-atomic argumentA
passed tof
,atomic_is_lock_free(A)
yieldstrue
.
std::atomic_flag
doesn't fit here formally (there is no is_lock_free
method and atomic_is_lock_free
can't be called with std::atomic_flag
object). Though intuitively, it's very close (it's atomic and lock-free). Does it mean that std::atomic_flag
can't be used in a signal handler, or it's just a C++ standard that needs clarification?
std::atomic_flag
is always lock free, so it seems to me like it should be usable in a signal handler, but I agree that it doesn't seem legal by the current wording. I don't see any existing standard defects relating to it. Assuming no one more knowledgable than myself has a better answer, there are instructions for submitting a standard defect report here. – Canticle