Solved

How to terminate a thread in vc++

Posted on 2008-10-04
3
728 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.

735 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