What's the equivalent of sleep(), wait(), or pause()
Sean Kelly
sean at f4.ca
Sat Jul 8 19:54:23 PDT 2006
Dave wrote:
> James Pelcis wrote:
>> In this case, the best solution would likely be std.c.time.
>>
>> # private import std.c.time, std.stdio;
>> #
>> # void main () {
>> # writefln("Hello World.");
>> # sleep(2);
>> # writefln("Goodbye World.");
>> # }
>>
>> 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?
>>
>
> There is a possibility in each of the phobos implementations (Windows
> and Linux) for an indefinite wait to happen, so an if(this is getThis())
> { error(...); } check is done.
>
> It looks like that potential is there to make these safe and still allow
> for the calling thread to call wait(uint) on itself though.
>
> But, I think a general purpose & portable 'sleep, msleep and/or usleep'
> is a good idea.
>
> sleep doesn't have > 1 sec. resolution, std.c.time.msleep is not in the
> std. C RT lib. on Linux systems, and usleep is deprecated on Linux, so
> the need is there for one.
>
> Where in Phobos should this go?
As a static function in the Thread class. See Ares for an example.
Sean
More information about the Digitalmars-d-learn
mailing list