title: Longjmp out of signal handler?
body: <p>From the question:</p>
  
  <p><a href="https://stackoverflow.com/questions/7262494/is-it-good-programming-practice-to-use-setjmp-and-longjmp-in-c">Is it good programming practice to use setjmp and longjmp in C?</a></p>
  
  <p>Two of the comments left said:</p>
  
  <blockquote>
    <p>"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."</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>This would seem to imply (to me) that they aren't called through your normal code.</p>
  
  <p>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!?</p>