[Haskell-cafe] accurately scheduling events

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Apr 11 04:04:12 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. When 
> I write
> 
> do action0
>    threadDelay t
>    action1

> then action1 is not started duration t after action0 is started, but time 
> t after action0 is finished.

You can try my prototype implementation of retryIfBefore/retryIfAfter
STM actions. Internally, it uses threadDelay (through a fake
registerTimeout), so it may have the same problems as threadDelay, but:
- IIRC, Simon Marlow implemented registerTimeout for GHC 6.6 - maybe
  it is more accurate than threadDelay... hmmm... I have HEAD somewhere,
  so I'll try how it works
- I could try some other waiting mechanism for short intervals

The use of retryIfBefore would be:

    do t0 <- getCurrentTime
       action0
       atomically (retryIfBefore (addUTCTime t t0))
       action1

but for such a simple task, something simpler could be better

The code is in a darcs repo here:
    http://www.uncurry.com/repos/stm-time/

Best regards
Tomasz


More information about the Haskell-Cafe mailing list