[pure-lang-svn] SF.net SVN: pure-lang:[479] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-13 01:07:38
|
Revision: 479 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=479&view=rev Author: agraef Date: 2008-08-13 01:07:48 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Add signal processing example. Modified Paths: -------------- pure/trunk/ChangeLog Added Paths: ----------- pure/trunk/examples/signal.pure Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-12 23:58:36 UTC (rev 478) +++ pure/trunk/ChangeLog 2008-08-13 01:07:48 UTC (rev 479) @@ -1,5 +1,7 @@ 2008-08-13 Albert Graef <Dr....@t-...> + * examples/signal.pure: Add signal processing example. + * runtime.cc (pure_catch, pure_invoke): Collecting temporary values after an exception doesn't seem to be safe while an evaluation is still in progress. Moved this to doeval/dodefn in Added: pure/trunk/examples/signal.pure =================================================================== --- pure/trunk/examples/signal.pure (rev 0) +++ pure/trunk/examples/signal.pure 2008-08-13 01:07:48 UTC (rev 479) @@ -0,0 +1,30 @@ + +/* Signal processing example. */ + +using system; +extern int getpid(); + +/* The common POSIX termination signals like SIGHUP, SIGINT, SIGTERM etc. are + already remapped to Pure exceptions by the interpreter when it starts. + Other kinds of signals can be handled as Pure exceptions, too, if we rebind + them with the 'trap' function. (Try 'list -g SIG*' to see which standard + signal values are known on your system.) Example: */ + +trap SIG_TRAP SIGTSTP; + +/* Running this function enters an endless loop reporting all signals + delivered to the process. */ + +test = printf "Running as pid %d, try to kill me!\n" getpid, loop; + +loop = loop when _ = catch sig check end +with + sig (signal k) = loop when _ = printf "Hey, I got signal %d.\n" k end; +end; + +/* Take a short nap so that the loop doesn't run busily. This also serves the + purpose of checking for pending signals. (Note that for performance reasons + the Pure interpreter only processes asynchronous signals at certain points, + such as the entry of a global Pure function.) */ + +check = sleep 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |