Solved

How to terminate a thread in vc++

Posted on 2008-10-04
3
721 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

772 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