Solved

How to terminate a thread in vc++

Posted on 2008-10-04
3
719 Views
Last Modified: 2013-12-14
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  
0
Comment
Question by:aureliuh
3 Comments
 
LVL 4

Accepted Solution

by:
petr_hlucin earned 500 total points
ID: 22640015
Since you access this variable for writing only from 1 thread (if I understand your code well) you don't need to use critical section. The worst situation that might occur is that 1 more iteration is performed after the Terminated flag is set.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22640022
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?


0
 

Author Closing Comment

by:aureliuh
ID: 31503000
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse insufficient memory error 3 102
Intellij adding new line in xml 3 69
Visual Studio community 2015 2 67
Android studio getdrawable(int) is deprecated 4 39
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now