简体   繁体   English

sig_atomic_t和std :: atomic <>是否可以互换?

[英]Are sig_atomic_t and std::atomic<> interchangable?

As per the title. 按照标题。 Can I use std::atomic<> in a signal handler or does sig_atomic_t provide other compiler features? 我可以在信号处理程序中使用std::atomic<>还是sig_atomic_t提供其他编译器功能?

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 当抽象机的处理由于接收到信号而中断时,既不是

— of type volatile std::sig_atomic_t nor —类型为volatile std :: sig_atomic_t或

— lock-free atomic objects (29.4) —无锁原子对象(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 无锁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. ATOMIC _..._ LOCK_FREE宏指示相应原子类型的无锁属性,其中有符号和无符号变体组合在一起。 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. 值为0表示这些类型永远不会无锁。 A value of 1 indicates that the types are sometimes lock-free. 值为1表示这些类型有时是无锁的。 A value of 2 indicates that the types are always lock-free. 值为2表示类型始终是无锁的。

The function atomic_is_lock_free (29.6) indicates whether the object is lock-free. 函数atomic_is_lock_free (29.6)指示对象是否无锁。 In any given program execution, the result of the lock-free query shall be consistent for all pointers of the same type. 在任何给定的程序执行中,对于相同类型的所有指针,无锁查询的结果应保持一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM