Is this a good way of setting up a timer?

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Jun 3 14:37:40 PDT 2011


On 6/3/11, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>
> Generally, you'd just put it to sleep for the period of time that you want
> to
> wait for. The only reason that I see to keep waking it up is if it could be
> interrupted and effectively told to wake up - in which case you would be
> sleeping and waking up over and over again, checking to see if enough time
> had
> passed or if you had been signaled to stop waiting.

Yeah, I should have made a better example. Basically I have a loop
that ends either after a specific time period, or it could end by
receiving a signal. I just use a shared book for that, this would be
it:

    while (engineActive)  // shared bool
    {
        if (Clock.currTime > finalTime)
            break;

        Thread.sleep(dur!("seconds")(1));
    }

> Oh,
> and
> by the way, std.datetime publicly imports core.time, so if you import
> std.datetime, you don't need to import core.time.
>
> - Jonathan M Davis
>

Ok thanks!


More information about the Digitalmars-d-learn mailing list