Are std::signal and std::raise thread-safe?

前端 未结 4 1878
粉色の甜心
粉色の甜心 2020-12-18 21:13

The C and C++ standards support the concept of signal. However, the C11 standard says that the function signal() cannot be called in multi-threaded environments, or the beha

4条回答
  •  悲&欢浪女
    2020-12-18 21:51

    I think you just misintrepret the term undefined behavior, which is unfortunately much overloaded to mean "bad things will happen". Here the term really just means what it says: the C standard doesn't make any assumption about what it means to use signal in a multi-threaded context.

    In general the signal/raise interface in the C standard is not very useful by itself, but only a placeholder for platform/OS specific things that are defined on top of it.

    So for an interaction between signal and threats doesn't give you a contract. Or stated otherwise, the interaction of signal and threads is left to the platform implementation.

提交回复
热议问题