Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 295
James Avatar asked Apr 11 '13 12:04

James


1 Answers

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.

like image 88
ForEveR Avatar answered Oct 21 '22 09:10

ForEveR