[erlang-questions] Minimum time for timer:sleep()?

James Hague <>
Mon Mar 19 23:01:40 CET 2007


Thanks everyone for the replies, though I still haven't worked out a
solution I'm happy with.  Here's the details of what I'm trying to do:

I have an Erlang program that communicates with an external graphics
"driver" program.  This way I can put pretty pictures on the screen
but without having to micromanage everything from Erlang itself.  What
I was attempting to do was to get updates running more or less at 60
Hz (16 microseconds per frame).

My first idea was to track execution time per frame, then sleep the
rest of the 16 millisecond slice.  This didn't work because sleep
waits a minimum of 10 milliseconds, regardless of the value passed in.

My second idea was to spawn a process at the start of a frame, wait 16
milliseconds in that process, then send a message to the original
process,  This works, except the 16 millisecond time can vary quite a
bit: from 16.8 ms to 22+ ms in my tests.

Any approaches to more precise timing would be appreciated!

James



More information about the erlang-questions mailing list