Are sig_atomic_t and std::atomic<> interchangable?

后端 未结 1 874
灰色年华
灰色年华 2020-12-03 11:21

As per the title. Can I use std::atomic<> in a signal handler or does sig_atomic_t provide other compiler features?

相关标签:
1条回答
  • 2020-12-03 11:58

    n3376 1.9/6

    When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects which are neither

    — of type volatile std::sig_atomic_t nor

    — lock-free atomic objects (29.4)

    are unspecified during the execution of the signal handler, and the value of any object not in either of these two categories that is modified by the handler becomes undefined.

    Lock-free 29.4/1,2

    The ATOMIC_..._LOCK_FREE macros indicate the lock-free property of the corresponding atomic types, with the signed and unsigned variants grouped together. The properties also apply to the corresponding (partial) specializations of the atomic template. A value of 0 indicates that the types are never lock-free. A value of 1 indicates that the types are sometimes lock-free. A value of 2 indicates that the types are always lock-free.

    The function atomic_is_lock_free (29.6) indicates whether the object is lock-free. In any given program execution, the result of the lock-free query shall be consistent for all pointers of the same type.

    0 讨论(0)
提交回复
热议问题