This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using async's in Guile.


"Bradley M. Kuhn" <bkuhn@ebb.org> writes:

> Hmmm...so, what is the best way now to handle a case where I need a clock to
> invoke some function after a specified amount of time.
>
> Right now, I am using a clock implementation that uses SIGALRM underneath.
> 
> I would like something a bit more versatile.
> 
> 
> Any suggestions?  Attached is my current implementation of the clock.

Is the exactness of time important?  One suggestion is to spawn a
thread for each clock:

(define (make-barizer foo ms)
  (let ((us (* ms 1000)))
    (begin-thread
      (let loop ()
        (usleep us)
        (foo)
        (loop)))))

Otherwise, it doesn't seem like a bad idea to use SIGALRM.  If you
want to be able to use several clocks, you can always write a layer
in-between which handles this.  (You use code which can support
multiple handlers.  This code, in turn, is based on SIGALRM.)

If 1 s is too small resolution, then you could use some other
interrupt, like the virtual timer.  (I'm not sure that Guile supports
that now, but it is easy to copy the code for the `alarm' primitive
and modify it into a virtual timer primitive.  If you do this, I can
include it in the distribution.)

/mdj

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]