How does sig_atomic_t actually work?

前端 未结 5 2079
梦谈多话
梦谈多话 2020-11-30 02:19

How does the compiler or OS distinguish between sig_atomic_t type and a normal int type variable, and ensures that the operation will be atomic? Programs using both have sam

5条回答
  •  暖寄归人
    2020-11-30 03:01

    sig_atomic_t is often just a typedef (to some system specific integral type, generally int or long). And it is very important to use volatile sig_atomic_t (not just sig_atomic_t alone).

    When you add the volatile keyword, the compiler has to avoid a lot of optimizations.

    The recent C11 standard added _Atomic and . You need a very recent GCC (e.g. 4.9) to have it supported.

提交回复
热议问题