Is this a good way of setting up a timer?

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jun 6 11:45:12 PDT 2011


On 6/6/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> Then, you have a function that sets the bool and signals the condition:
>
> void endProgram()
> {
>     synchronized(mutex)
>     {
>        if(engineActive)
>        {
>            engineActive = false;
>            cond.notifyAll();
>        }
>     }
> }

Interesting, thanks. There's some WinAPI functions like
WaitForMultipleObjects, I've read about them too.

Other than that, the while loop will go away and be replaced with some
kind of front-end for the user (e.g. GUI), while the background thread
crunches some numbers. The background thread should be able to signal
if something went wrong. Throwing exceptions from the work thread is
off limits, because they don't propagate to the foreground thread, so
I'm left with either using some kind of global boolean or I'd use
std.concurrency.send() to signal that something went wrong.


More information about the Digitalmars-d-learn mailing list