如果我从信号处理程序调用 syscall(SYS_gettid) 会产生什么影响?
有人可以告诉我从信号处理程序调用 syscall(SYS_gettid) 可能会产生什么不利影响吗? 我知道它不在从信号处理程序调用的安全函数列表中,但我想知道其背后的原因?
Can some one tell me what could be the adverse effect of calling syscall(SYS_gettid) from Signal Handler?
I know it is not in the safe functions list to be called from signal handler but I want to know reason behind it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定这与信号处理程序方法的可重入有关。假设发送了一个信号,并且您的处理程序捕获该信号并开始处理。在处理时,并发程序可能会发送另一个信号,并且您的处理程序再次捕获该信号并开始处理它。
根据调度的工作方式,同一代码块(信号处理程序)可能在其自身执行期间执行。问题是它使用相同的指针和变量,因此它可能会损坏自身,特别是因为 gettid() 返回当前线程的 ID。在这种情况下,当前线程是哪个?
I'm pretty sure this has to do with the Signal Handler methods being reentrant. Suppose a signal is sent, and your handler grabs the signal and starts processing. While processing, another signal may be sent by a concurrent program, and your handler again grabs that signal, and starts processing it.
Depending on how the scheduling works out, it's possible that the same chunk of code, the Signal Handler, executes during its own execution. The problem is that it uses the same pointers and variables, so it can corrupt itself, especially because gettid() returns the ID of the current thread. Which is the current thread in this case?