[Haskell-cafe] accurately scheduling events

John Meacham john at repetae.net
Mon Apr 10 19:21:58 EDT 2006

On Mon, Apr 10, 2006 at 02:40:20PM +0200, Henning Thielemann wrote:
> My question: Is there some more accurate time scheduling available? Maybe 
> not only a more accurate 'wait' function but a function which processes a 
> list of events and starts the actions at the appropriate time points.

what system are you on? if you are on linux, the best thing is to use
the 'real time clock' interface, which can be accessed at


there is documentation available online, but basically you can set it up
to give you periodic interrupts at any interval, you then want to use
'threadWaitRead' in a loop to wait for each event.

spawning another OS bound thread that uses 'usleep' and writes a byte to
a pipe which you are doing the threadWaitRead loop on might work too and
be more portable, but I am not quite sure what issues are involved with
ghc not handling ^C right away and whether an alternate bound thread
will block it.

you can always write a little C stub that will create that thread and
return to haskell immediatly.

but if possible, the rtc is designed for such a use.

you might also look into /dev/sequencer, but that is tied to your sound
card hardware which may or may not be acceptable.

also see the c routine 'setitimer' which can be set up to periodically
deliver a signal to you and should be very precise. I am not sure if
haskell will give you enough control to deal with the signal with the
latency you want, but it is also worth a try. 


John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list