gpt4 book ai didi

c - setitimer 的 ITIMER_PROF(SIGPROF) 是否发送到多线程和 NPTL 以及 Linux(2.6.21.7) 中的每个线程?

转载 作者:IT王子 更新时间:2023-10-29 00:39:49 25 4
gpt4 key购买 nike

手册说 setitimer 在整个 PROCESS 中共享,SIGPROF 发送到 PROCESS 而不是线程。

但是当我在我的多线程进程中创建计时器时,除非我为进程中的每个线程创建独立的堆栈来处理信号,否则我将在信号处理程序中遇到一些非常严重的错误。通过一些调试,我确认堆栈(sole stack case)一定已经重新进入了。

所以现在我怀疑 SIGPROF 可能会同时发送到多线程?谢谢!

最佳答案

我不了解你问题的细节,但一般情况是:

A signal may be generated (and thus pending) for a process as a whole (e.g., when sent using kill(2)) or for a specific thread (e.g., certain signals, such as SIGSEGV and SIGFPE, generated as a consequence of executing a specific machine-language instruction are thread directed, as are signals targeted at a specific thread using pthread_kill(3)). A process-directed signal may be delivered to any one of the threads that does not currently have the signal blocked. If more than one of the threads has the signal unblocked, then the kernel chooses an arbitrary thread to which to deliver the signal.

man (7) signal

您可以使用 pthread_sigmask 来阻止特定线程的信号并通过消除将其定向到您要处理它的线程。

关于c - setitimer 的 ITIMER_PROF(SIGPROF) 是否发送到多线程和 NPTL 以及 Linux(2.6.21.7) 中的每个线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5499414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com