[erlang-questions] Minimum time for timer:sleep()?
Wed Mar 21 14:30:28 CET 2007
I ended up using something along the lines of Bob's solution, sleeping
for 10 millisecond chunks and then busy-waiting the rest. I've gotta
admit that busy-waiting on such a fast machine feels completely wrong
to me--but it does give almost microsecond-perfect timing.
I spawn the wait loop into its own process, to minimize the garbage
collection times caused by flooding memory with tuples from now/1 and
When I got around to trying this under Windows, I found sleep is even
worse than under OS X. The minimum sleep time is 16,000 microseconds
(compared to 10,000) and the drift is all over the place: sleep(100)
takes 110,000 microseconds, sleep(20) takes 31,000 microseconds. So
now I'm busy-waiting all the time; no calls to sleep.
I'm getting a much better appreciation for what it takes to push
Erlang in a slightly harder real-time direction. I'll post the
results of further experiments when I have time to work through them.
More information about the erlang-questions