digitalmars.D.learn - What's the equivalent of sleep(), wait(), or pause()
- Charles D Hixson (8/8) Jul 08 2006 Alternatively, where in the documentation can I find it.
- James Pelcis (21/30) Jul 08 2006 In this case, the best solution would likely be std.c.time.
- Dave (12/46) Jul 08 2006 There is a possibility in each of the phobos implementations (Windows
- Regan Heath (3/6) Jul 08 2006 FYI; There exists a function called "nanosleep" on some unix OS's.
- Dave (3/11) Jul 08 2006 Yep, that's what I'd use to implement the guts of portable and signal
- Sean Kelly (3/45) Jul 08 2006 As a static function in the Thread class. See Ares for an example.
- Mike Parker (6/21) Jul 09 2006 Thread.wait() is not a sleep method - it's what is sometimes called a
- James Pelcis (5/9) Jul 09 2006 Thread.wait() is indeed that. If, however, you pass an integer, it will...
-
Derek Parnell
(7/7)
Jul 09 2006
Valium();
Alternatively, where in the documentation can I find it. What I want to do is to wait for a couple of seconds with a message on the screen before continuing. I thought I knew the answer (sleep(2) ), but that was the bash command...what's the D equivalent? Or do I just need to build a do-nothing loop with a LONG countdown? (That would be a bad answer, because I don't really want to eat system resources just because I'm waiting.)
Jul 08 2006
In this case, the best solution would likely be std.c.time. 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... 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? Charles D Hixson wrote:Alternatively, where in the documentation can I find it. What I want to do is to wait for a couple of seconds with a message on the screen before continuing. I thought I knew the answer (sleep(2) ), but that was the bash command...what's the D equivalent? Or do I just need to build a do-nothing loop with a LONG countdown? (That would be a bad answer, because I don't really want to eat system resources just because I'm waiting.)
Jul 08 2006
James Pelcis wrote:In this case, the best solution would likely be std.c.time. 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... 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?Charles D Hixson wrote:Alternatively, where in the documentation can I find it. What I want to do is to wait for a couple of seconds with a message on the screen before continuing. I thought I knew the answer (sleep(2) ), but that was the bash command...what's the D equivalent? Or do I just need to build a do-nothing loop with a LONG countdown? (That would be a bad answer, because I don't really want to eat system resources just because I'm waiting.)
Jul 08 2006
On Sat, 08 Jul 2006 19:06:13 -0500, Dave <Dave_member pathlink.com> wrote: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.FYI; There exists a function called "nanosleep" on some unix OS's. Regan
Jul 08 2006
Regan Heath wrote:On Sat, 08 Jul 2006 19:06:13 -0500, Dave <Dave_member pathlink.com> wrote:Yep, that's what I'd use to implement the guts of portable and signal consistent 's/ms/usleep' functions on Linux.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.FYI; There exists a function called "nanosleep" on some unix OS's. Regan
Jul 08 2006
Dave wrote:James Pelcis wrote:As a static function in the Thread class. See Ares for an example. SeanIn this case, the best solution would likely be std.c.time. 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... 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?
Jul 08 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... 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.
Jul 09 2006
> Thread.wait() is not a sleep method - it's what is sometimes called ajoin (as in Java) - it waits for a thread to finish execution. A thread cannot wait for itself to finish, hence the error.Thread.wait() is indeed that. If, however, you pass an integer, it will wait until it is either terminated or that number of milliseconds has passed. I think the check should be removed for that version.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.I agree.
Jul 09 2006
Valium(); <G> -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 10/07/2006 11:16:54 AM
Jul 09 2006