Weird timing issue with Thread.sleep
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Aug 3 10:14:50 PDT 2011
Take a look at this:
import std.stdio;
import core.thread;
void main()
{
foreach (x; 0 .. 1000)
{
Thread.sleep(dur!("usecs")(999));
writeln(x);
}
foreach (x; 0 .. 1000)
{
Thread.sleep(dur!("usecs")(1000));
writeln(x);
}
}
Compile and run it. The first foreach loop ends in an instant, while
the second one takes much much longer to finish, which is puzzling
since I've only increased the sleep while for a single microsecond.
What's going on?
More information about the Digitalmars-d-learn
mailing list