☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

在多线程环境中不可使用 signal 函数

16.9 ID_signalInMultiThreading
目录 › next › previous

在多线程环境中使用 signal 函数会导致标准未定义的行为。

示例:

#include <signal.h>
#include <threads.h>

void handler(int);

int thread(void* param) {
    signal(SIGINT, handler);  // Non-compliant, undefined behavior
    ....
}

例中 thread 是线程函数,C11 标准指明在多线程环境中使用 signal 函数会导致未定义的行为。

相关

ID_forbidSignalFunction

依据

ISO/IEC 9899:2011 7.14.1.1(7)-undefined

参考

SEI CERT CON37-C
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.