Date
2022-08-18.00:00:00
Message id
12721

Content

Following document number N4910 about signal-safe instructions [support.signal] Signal handlers, and it's unclear whether std::atomic_flag is signal-safe.

Formally it doesn't fit any of the mentioned conditions:

  • f is a non-static member function invoked on an object A, such that A.is_lock_free() yields true, or

    (there is no is_lock_free method in std::atomic_flag class)

  • f is a non-member function, and for every pointer-to-atomic argument A passed to f, atomic_is_lock_free(A) yields true

    (std::atomic_flag object can't be passed to atomic_is_lock_free as argument)

However, std::atomic_flag seem to fit well here, it's atomic, and it's always lock-free.

The suggestion is as follows: If std::atomic_flag is signal-safe, then it should be explicitly mentioned in [support.signal], e.g., the following lines should be added:

  • f is a non-static member function invoked on an atomic_flag object, or

  • f is a non-member function, and every pointer-to-atomic argument passed to f is atomic_flag, or

If the std::atomic_flag is not signal-safe, the following note could be added:

[Note: Even though atomic_flag is atomic and lock-free, it's not signal-safe. — end note]