Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to terminate a thread in vc++

Posted on 2008-10-04
3
Medium Priority
?
745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
petr_hlucin earned 2000 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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 column That will then direct you to their download page. From that p…
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…

688 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