longjmp的输出信号处理的? [英] Longjmp out of signal handler?

查看:123
本文介绍了longjmp的输出信号处理的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从问题:

<一个href=\"http://stackoverflow.com/questions/7262494/is-it-good-programming-practice-to-use-setjmp-and-longjmp-in-c\">Is它良好的编程习惯使用的setjmp和longjmp使用C?

留下的评论,两个说:

你不能在信号处理程序抛出异常,但你可以做一个
  longjmp的安全 - 只要你知道自己在做什么。 - 迪特里希
  埃普8月31日19:57时
         @Dietrich:+1您的评论。这是一个鲜为人知的和
  完全-下-AP preciated事实。有许多的问题,即
  不能得到解决(讨厌的比赛条件),而无需使用longjmp的出
  信号处理程序。阻塞系统调用的异步中断是
  典型的例子。

"You can't throw an exception in a signal handler, but you can do a longjmp safely -- as long as you know what you are doing. – Dietrich Epp Aug 31 at 19:57 @Dietrich: +1 to your comment. This is a little-known and completely-under-appreciated fact. There are a number of problems that cannot be solved (nasty race conditions) without using longjmp out of signal handlers. Asynchronous interruption of blocking syscalls is the classic example."

我是IM pression的信号处理是由内核调用时就遇到异常情况(如除以0)下。同样,他们只是叫你专门注册。

I was under the impression that signal handlers were called by the kernel when it encountered an exceptional condition (e.g. divide by 0). Also, that they're only called if you specifically register them.

这似乎意味着(我),他们没有通过正常的code调用。

This would seem to imply (to me) that they aren't called through your normal code.

与思想...... setjmp和longjmp的移动作为我理解他们是堆栈崩溃多达previous点和状态。我不明白你如何瓦解一个堆栈时,因为从它的内核称为一个一次性的情况下,而不是从自己的code信号处理函数。什么是未来的事情从信号处理程序堆栈!?

Moving on with that thought... setjmp and longjmp as I understand them are for collapsing up the stack to a previous point and state. I don't understand how you can collapse up a stack when a signal handler is called since its called from the Kernel as a one-off circumstance rather than from your own code. What's the next thing up the stack from a signal handler!?

推荐答案

的longjmp 不执行正常的堆栈展开。相反,堆栈指针只是由的setjmp 保存的情况下恢复。

longjmp does not perform normal stack unwinding. Instead, the stack pointer is simply restored from the context saved by setjmp.

这里是如何能咬你一个例证在code非异步安全的关键部件。最好是如关键code时遮住违规的信号。

Here is an illustration on how this can bite you with non-async-safe critical parts in your code. It is advisable to e.g. mask the offending signal during critical code.

这篇关于longjmp的输出信号处理的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆