[Openmcl-devel] Timers...

Gary Byers gb at clozure.com
Thu Jun 4 00:49:14 PDT 2009


This seems generally reasonable.  There's always a chance that the
semaphore would have been seen to b signaled if only the timeout had
been slightly longer, so the target thread might complete its work,
signal the semaphore, and then get an interrupt.  Depending on the
application, that may or may not be significant.

On Wed, 3 Jun 2009, Jon S. Anthony wrote:

> Hi,
>
> I'm porting a system to CCL and one bit I've come up to is a with-timer
> capability.  Is something like this pretty much the "right" way to
> achieve this in CCL?  I know about Dan Corkill's variant (in
> "portable-threads"), but this seems a bit better.  Yes?  No?
>
>
> #+ccl
> (defun interrupt-timer (interruptable-process semaphore duration func)
>  (let ((work-done (ccl:timed-wait-on-semaphore semaphore duration)))
>    (when (not work-done)
>      (ccl:process-interrupt
>       interruptable-process
>       func))))
>
> #+ccl
> (defmacro with-timer ((seconds-available &body timeout-forms) &body
> body)
>  (with-gensyms (semaphore tag)
>    `(let* ((,semaphore (ccl:make-semaphore))
>            (,tag (gensym)))
>       (ccl:process-run-function
>        "timer-proc"
>        #'interrupt-timer
>        ccl:*current-process*
>        ,semaphore ,seconds-available
>        #'(lambda () (throw ,tag (progn , at timeout-forms))))
>       (catch ,tag
>         (unwind-protect
>            (progn , at body)
>           (ccl:signal-semaphore ,semaphore))) )))
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list