On Tue, Jul 6, 2010 at 11:52 AM, Gary Byers <span dir="ltr"><<a href="mailto:gb@clozure.com">gb@clozure.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
<br>
On Tue, 6 Jul 2010, Daniel Weinreb wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You added ccl:*quit-interrupt-hook*, which is called<br>
on SIGTERM. Does it have these problems?<br>
</blockquote>
<br></div>
No.<br>
<br>
There's a handler for SIGTERM (and SIGINT and IIRC SIGQUIT)<br>
in the lisp kernel; it just sets a flag in memory indicating<br>
which of those signals have been received since the flag was<br>
last cleared.<br>
<br>
Some lisp code that runs a few times a second checks/clears that flag<br>
and interrupts some thread. There are a few hooks that give a little<br>
bit of control over what thread gets interrupted and (in the case of<br>
SIGQUIT/SIGTERM) what function gets called. That's (at most) just a<br>
matter of interrupting a thread via PROCESS-INTERRUPT, and<br>
PROCESS-INTERRUPT tries to be very careful about when/how the target<br>
thread is interrupted.<br>
<br>
A more general mechanism would allow you to do something like:<br>
<br>
(define-signal-handler SIGQUIT<br>
;; This runs on an arbitrary thread at a more-or-less arbitrary<br>
;; time. The implementation has ensured that it's GC-safe to<br>
;; run lisp code now; beyond that, you have enough rope to hang<br>
;; yourself in lots of ways, and you may not be able to safely<br>
;; do too much more than set a flag here.<br>
(arbitrary-code ...))<br>
<br>
but that mechanism doesn't exist and would require some implementation<br>
support to even offer the GC-safety that the comment describes.<br><br></blockquote><div> </div></div>But couldn't this mechanism be implemented in exactly the same way as you have described doing for SIGTERM? It would certainly be adequate for my needs; I don't need microsecond response times (though 250ms would be a bit on the long side; maybe the poll rate of "a few times a second" needs to be 20/sec or so).<br>
<br>-- Scott<br><br>