Solved

terminate all child threads

Posted on 2003-10-28
6
177 Views
Last Modified: 2013-11-20
I have this program that creates many threads that updates a screen with data .When i stop the program to clear the screen it crashes.So can anyone tell me how to stop all other threads without closing the main window(gui).I want to close all threads and leave the screen as it is,

Thanks.
0
Comment
Question by:rc3000
  • 4
6 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636256
I can't understand what you mean.
But you can "close thread" by calling TerminateThread.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636277
But keep in mind that:

TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.

TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636302
So the proper way is to "say" the thread, that it must stop by setting a variable or an event.
The thread have to check the variable or event in it's execution loop.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:rc3000
ID: 9636365
hi gloomy ,
   your answer is also gloomy for me.Because if i use terminatethread then the window closes and some other threads continue to run.If i use Exitprocess(0) then it exits gracefully but the window closes .I want the window the main window to remain open while all  the background processing comes to a stop.I hope this clarifies things.I am increasing the number of points by 100.
0
 
LVL 13

Accepted Solution

by:
SteH earned 135 total points
ID: 9640280
The example on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_MTGDI.asp
should be very helpful for your purpose. There several (hundred) threads can be started and stopped without affecting the main program.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9640401
I still don't understand what all this about.
Let's go step-by-step.
How do you create the threads and what the thread have to do?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

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