Thread.sleep (DMD 2.020)
John C
johnch_atms at hotmail.com
Sun Nov 2 10:39:28 PST 2008
Sean Kelly Wrote:
> torhu wrote:
> > Sean Kelly wrote:
> >> John C wrote:
> > ...
> >>> Win32's Sleep(50) seems to be the same as Thread.sleep(500_000). Is
> >>> that right?
> >>
> >> Yup. There should probably be some sort of TimeSpan struct to help
> >> prevent these mistakes.
> >
> > I assume people won't need a higher resolution than milliseconds that
> > often. Could Thread.sleep be changed into something like this?
> >
> > Thread.sleep(long millis, long hundredsOfNanos=0);
>
> While Windows uses milliseconds, *nix uses either micrososeconds
> (usleep) or a combination of seconds and nanoseconds (nanosleep), so
> while using milliseconds may be more natural for Windows users it's
> liable to confuse others. I suppose what I'm getting at is that there's
> no resolution that's natural for everyone, and accepting a raw integer
> as a timespan is going to cause problems no matter what resolution is
> chosen--it's just too easy to get the number of zeros wrong. So I'd
> rather aim for establishing a structured form of time representation
> than to try and tweak the current setup. In the interim, Tango users
> will be happy to note that Thread.sleep() uses the same resolution as
> TimeSpan uses internally, so calling this routine from Tango using a
> TimeSpan should be pretty straightforward.
>
>
> Sean
It is:
import tango.time.Time, core.thread;
Thread.sleep(TimeSpan.fromMillis(50).ticks);
More information about the Digitalmars-d
mailing list