D - Sleep function
- Brad Anderson <brad sankaty.com> Aug 20 2003
- "Mike Wynn" <mike.wynn l8night.co.uk> Aug 20 2003
- Ant <Ant_member pathlink.com> Aug 26 2003
Does anyone have ideas on how to write a native D program that would
sleep for X seconds / milliseconds / useconds ?? The most important
feature is to not take CPU cycles while waiting.
I'm a newbie, and wondering if you have to make any OS-specific calls,
or if it's architecture-specific (i386). Basically I want to duplicate
the Sleep(DWORD dwMilliseconds) call in windows.d or sleep() and
usleep() in Linux to make a native D cross-platform utility for our Std.
D Lib. (or whatever we call it).
Am I asking for too much trouble? Will this always be OS-specific, and
I'm better off just doing a version(Win32) {} and version(Linux) {} and
calling the existing utils?
Thanks,
Brad
Aug 20 2003
"Brad Anderson" <brad sankaty.com> wrote in message news:bi1jed$1ipp$1 digitaldaemon.com...Does anyone have ideas on how to write a native D program that would sleep for X seconds / milliseconds / useconds ?? The most important feature is to not take CPU cycles while waiting. I'm a newbie, and wondering if you have to make any OS-specific calls, or if it's architecture-specific (i386). Basically I want to duplicate the Sleep(DWORD dwMilliseconds) call in windows.d or sleep() and usleep() in Linux to make a native D cross-platform utility for our Std. D Lib. (or whatever we call it). Am I asking for too much trouble? Will this always be OS-specific, and I'm better off just doing a version(Win32) {} and version(Linux) {} and calling the existing utils?
I would use the OS provided `sleep` functions, some OS's (like linux, netbsd) run on several arch's and the last thing you want to do is a busy wait or send a "halt" to the CPU especially in an multi threaded or multi process env. on windows you might want to look at the docs on `MsgWaitForMultipleObjects` which is interruptable on conditions such as new message, I would assume that there is a similar under linux may be a `select` with the msg queue filehandle.
Aug 20 2003
In article <bi1jed$1ipp$1 digitaldaemon.com>, Brad Anderson says...Does anyone have ideas on how to write a native D program that would sleep for X seconds / milliseconds / useconds ?? The most important feature is to not take CPU cycles while waiting. ...
You know, if you import time you have (Linux): sleep(2); // 2 seconds msleep(???) // dosn't work for me usleep(2_000_000); // 2 seconds (from memory, check src/phobos/time.d) Ant
Aug 26 2003









"Mike Wynn" <mike.wynn l8night.co.uk> 