<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>7.2. Kinds of signals</title><link rel="stylesheet" href="ecl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><link rel="home" href="index.html" title="The ECL manual"><link rel="up" href="ch22.html" title="Chapter 7. Signals and interrupts"><link rel="prev" href="ch22.html" title="Chapter 7. Signals and interrupts"><link rel="next" href="ch22s03.html" title="7.3. Signals and interrupts in ECL"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7.2. Kinds of signals</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch22.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Signals and interrupts</th><td width="20%" align="right"> <a accesskey="n" href="ch22s03.html">Next</a></td></tr></table><hr></div><div class="section" title="7.2. Kinds of signals"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ext.signals.kinds"></a>7.2. Kinds of signals</h2></div></div></div><div class="section" title="7.2.1. Synchronous signals"><div class="titlepage"><div><div><h3 class="title"><a name="ext.signals.synchronous"></a>7.2.1. Synchronous signals</h3></div></div></div><p>The name derives from POSIX and it denotes interrupts that occur due to the code that a particular thread executes. They are largely equivalent to C++ and Java exceptions, and in Windows they are called "unchecked exceptions."</p><p>Common Lisp programs may generate mostly three kinds of synchronous signals:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Floating point exceptions, that result from overflows in computations, division by zero, and so on.</p></li><li class="listitem"><p>Access violations, such as dereferencing NULL pointers, writing into regions of memory that are protected, etc.</p></li><li class="listitem"><p>Process interrupts.</p></li></ul></div><p>The first family of signals are generated by the floating point processing hardware in the computer, and they typically happen when code is compiled with low security settings, performing mathematical operations without checks.</p><p>The second family of signals may seem are, but unfortunately they still happen quite often. One scenario is wrong code that handles memory directly via FFI. Another one is undetected stack overflows, which typically result in access to protected memory regions. Finally, a very common cause of this kind of exceptions is invoking a function that has been compiled with very low security settings with arguments that are not of the expected type -- for instance, passing a float when a structure is expected.</p><p>The third family is related to the multiprocessing capabilities in Common Lisp systems and more precisely to the <a class="xref" href="re17.html" title="mp:interrupt-process"><code class="function">mp:interrupt-process</code></a> function which is used to kill, interrupt and inspect arbitrary threads. In POSIX systems <span class="application">ECL</span> informs a given thread about the need to interrupt its execution by sending a particular signal from the set which is available to the user.</p><p>Note that in neither of these cases we should let the signal pass unnoticed. Access violations and floating point exceptions may propagate through the program causing more harm than it is wished for, and without process interrupts we will not be able to stop and cancel different threads. The only question that remains, though, is whether such signals can be handled by the thread in which they were generated and how.</p></div><div class="section" title="7.2.2. Asynchronous signals"><div class="titlepage"><div><div><h3 class="title"><a name="ext.signals.asynchronous"></a>7.2.2. Asynchronous signals</h3></div></div></div><p>In addition to the set of synchronous signals or "exceptions", we have a set of signals that denote "events", things that happen while the program is being executed, and "requests". Some typical examples are:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Request for program termination (SIGKILL, SIGTERM).</p></li><li class="listitem"><p>Indication that a child process has finished.</p></li><li class="listitem"><p>Request for program interruption (SIGINT), typically as a consecuence of pressing a key combination, Ctrl-C.</p></li></ul></div><p>The important difference with synchronous signals is that we have no thread that causes the interrupt and thus there is no preferred way of handling them. Moreover, the operating system will typically dispatch these signals to an arbitrary thread, unless we set up mechanisms to prevent it. This can have nasty consequences if the incoming signal interrupt a system call, or leaves the interrupted thread in an inconsistent state.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch22.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch22.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch22s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Signals and interrupts </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 7.3. Signals and interrupts in <span class="application">ECL</span></td></tr></table></div></body></html>