Link to home
Start Free TrialLog in
Avatar of aureliuh
aureliuh

asked on

How to terminate a thread in vc++

Hello,

I have a thread and in this thread I have a while. it looks something like this:

 DWORD WINAPI  Thread(void* lpvParam)
{
    while (!Terminated)
    {
           // Do something

     }
}

The Terminated flag will be modified from another thread. My question is that should I use Critical_Section to protect the Terminated flag?

Thank you  
ASKER CERTIFIED SOLUTION
Avatar of petr_hlucin
petr_hlucin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndyAinscow
A boolean variable should be OK without a critical section.
However would it really hurt you to use a critical section in terms of performance if you are really worried?


Avatar of aureliuh
aureliuh

ASKER

Thank you