www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - More updated question about Sleep/msleep/usleep

reply "BeschBesch" <d475502 drdrb.com> writes:
Hello,

I know there are severel threads concerning "Wait", "Pause", 
"Sleep", a.s.o
but most of them were created in 2007 or similiar. It seems D has 
changed a lot because when I try to call sleep/msleep (example), 
the compiler cannot find it (ERROR: undefined indentifier).

import std.stdio;
/// .... other imports as well

import std.c.time;

main_bock()
{
//// init and things

sleep(1); // not found

std.c.time.sleep(2); // not found as well

std.c.time.msleep(1000); // nope...


/// continued code
}

So, is there a newer version? I get a hint for thread.sleep but 
this may be a member function. Also, i suppose I MAY use Sleep() 
from windows.h, if there is no other option.
Mar 22 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
import core.thread;

void main() {

}
Mar 22 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
This will work:

import core.thread;

void main() {
      Thread.sleep(5.seconds);
}


sleep is a member of Thread, but it is static so you can easily 
call it to sleep the current thread.

The argument is a Duration, which is most easily constructed with 
the .seconds, .msecs, .minutes, etc. helper functions like I did 
here.
Mar 22 2014