[Nickle] SIGINT and thread termination rules
keithp at keithp.com
Tue Feb 5 20:50:47 PST 2008
Carl Worth and I were hacking up some Unix domain socket support in
Nickle as a part of a project to implement Telepathy support on top of
Carl discovered that when an application created a Unix domain socket
and bound it to a filesystem name, the related inode would persist past
the life of the application. He wanted to clean up on exit so that the
next run of the application would be able to use the same name.
Unfortunately, nickle would often exit unceremoniously, either as a
result of SIGINT from ^C or at the end of the parser input.
I made two changes and thought they deserved a bit of discussion before
I released them.
The simpler change was to make the runtime system persist until all
threads were terminated, instead of exiting when the parser input was
exhausted. That seems fairly uncontroversial to me:
diff --git a/main.c b/main.c
index 491b390..2456c13 100644
@@ -107,6 +107,8 @@ main (int argc, char **argv)
(void) yyparse ();
+ /* Wait for any running threads to execute */
+ ThreadsRun (0, 0);
The second, and far more pervasive, change was to convert SIGINT into an
exception delivered to every thread. This eliminates the ability for
SIGINT to suspend thread execution so that they can be inspected by a
debugger and restarted. Instead, each thread receives a 'signal'
exception and is free to catch it and deal with it however they like.
Exceptions which are not caught terminate the thread with an error
> while (true);
(press ^C here)...
Unhandled exception signal (2)
<stdin>:1: while (true)
This certainly seems more useful for application development as
applications can expect that twixt blocks will *always* get executed,
even if the application receives a SIGINT or the parser sees EOF.
However, if 'exit' is called, the threads do not get a chance to clean
up -- the process exits immediately taking all threads down with it.
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: This is a digitally signed message part
Url : /pipermail/nickle/attachments/20080205/5294b1fb/attachment.pgp
More information about the Nickle