是sig_atomic_t和std :: atomic<>可互换 [英] Are sig_atomic_t and std::atomic<> interchangable
问题描述
按标题。我可以在信号处理程序中使用 std :: atomic<>
,或者 sig_atomic_t
p>
As per the title. Can I use std::atomic<>
in a signal handler or does sig_atomic_t
provide other compiler features?
推荐答案
n3376 1.9 / 6
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
- 类型volatile std :: sig_atomic_t也不
— of type volatile std::sig_atomic_t nor
- 无锁原子对象(29.4)
— 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.
无锁29.4 / 1,2
Lock-free 29.4/1,2
ATOMIC _..._ LOCK_FREE宏指示相应原子类型的无锁属性,
分组在一起的有符号和无符号变体。属性也适用于原子模板的相应(部分)
特化。值为0表示类型从不是无锁的。值
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.
函数 atomic_is_lock_free (29.6)表示对象是否无锁。在任何给定的程序
执行中,无锁查询的结果应该对于相同类型的所有指针是一致的。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.
这篇关于是sig_atomic_t和std :: atomic<>可互换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!