The with-timeout macro in this example:
(with-timeout 3 (sleep 5))
expands to this:
(IF (> 3 0)
(LET ((#:TIMER1102 (MAKE-TIMER (LAMBDA () (CERROR "Continue" 'TIMEOUT)))))
(SCHEDULE-TIMER #:TIMER1102 3)
(UNWIND-PROTECT (PROGN (SLEEP 5)) (UNSCHEDULE-TIMER #:TIMER1102)))
(PROGN (SLEEP 5)))
There are two problems,
1 The interface to WITH-TIMEOUT is different from the interface to MAKE-TIMER
2 When the time is a literal as in my example, the compiler produces a note:
; note: deleting unreachable code
Normally I investigate these messages, because they often indicate a program
So I tend to use this definition in stead:
(defmacro with-timeout (duration &rest forms)
(let ((timer (gensym "WITH-TIMEOUT-TIMER")))
`(LET ((,timer (MAKE-TIMER (LAMBDA () (CERROR "Continue" 'TIMEOUT)))))
(SCHEDULE-TIMER ,timer ,duration)
(PROGN ,@forms )
This is the same, but the test on expires/duration is gone.
I guess this is an example of premature error checking.
3 The condition type is derived from "serious-condition", which means it
rises through "ignore-errors" and "unwind-protect", but I chose to keep
it like that and in stead catch it where needed.
I don't have a patch, I don't completely understand the code which
probably is in src/code/timer.lisp.
Johan Ur Riise