Re: event vs volatile bool

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Arkady Frenkel (arkadyf_at_hotmailxdotx.com)
Date: 11/03/04


Date: Wed, 3 Nov 2004 14:50:22 +0200

In your case it's the same but in really you don't need while loop in the
case of event , just after another thread set event your
WaitForSingleObject will awake and do the business , that difference between
polling scenario vs. notification
Arkady

"manu" <manu@manu.net> wrote in message
news:esp4nYYwEHA.1564@TK2MSFTNGP09.phx.gbl...
> Hi everyone,
>
> Into a service, to communicate between threads, I use to test a volatile
> bool, like g_bRunning:
>
> while (g_bRunning)
> {
> // do the stuff
>
> Sleep(1000);
> }
>
> the other thread set the g_bRunning to false when they want to stop the
> others threads/
>
> what is the differences with: create an event, and wait for it:
>
> while(WaitForSingleObject(hStopEvent, 1000) != WAIT_OBJECT_0)
> {
>
> // do the stuff
> }
>
> ????
>
> thanks
>
>



Relevant Pages

  • Re: event vs volatile bool
    ... > In your case it's the same but in really you don't need while loop in the ... just after another thread set event your ... after 100, 1000 seconds, that stops everything. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Why cant I start a thread twice?
    ... Since the variable isn't marked as "volatile", ... are both free to make optimizations to access to the variable, ... thread set the variable to a particular value, ... a guarantee, ...
    (comp.lang.java.programmer)
  • event vs volatile bool
    ... Into a service, to communicate between threads, I use to test a volatile ... bool, like g_bRunning: ... the other thread set the g_bRunning to false when they want to stop the ...
    (microsoft.public.win32.programmer.kernel)