What's the equivalent of sleep(), wait(), or pause()
Mike Parker
aldacron71 at yahoo.com
Sun Jul 9 17:42:02 PDT 2006
James Pelcis wrote:
>
> I don't know of any pure D ways to do this in Phobos. The closest I
> could think of is in std.thread and is specifically prohibited...
>
> # private import std.thread, std.stdio;
> #
> # void main () {
> # writefln("Hello World.");
> # std.thread.Thread.getThis.wait(2000);
> # writefln("Goodbye World.");
> # }
>
> I don't know why that is though. My guess would be it's to cover up
> limitations in the operating system thread implementations. Can anyone
> confirm that?
Thread.wait() is not a sleep method - it's what is sometimes called a
join (as in Java) - it waits for a thread to finish execution. A thread
cannot wait for itself to finish, hence the error.
We have a static Thread.yield() method and I don't know why there's no
Thread.sleep(). It would be nice to have as a cross-platform solution.
More information about the Digitalmars-d-learn
mailing list