Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate a thread? 2

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hello,
I create a thread with this code

MainThread *Thread = new MainThread(false);

It runs fine, when I am finished with it, how do I terminate it?

Thanks
 
Have you tried:
Code:
MainThread->Terminate()

James P. Cottingham

There's no place like 127.0.0.1.
There's no place like 127.0.0.1.
 
This is a little tricky. It depends on how you use the thread. If you are going to create the thread many times in a program instance, you need to be careful. If you just create the thread when the program starts up and destroy the thread when the program ends, you can just call Terminate().

I like to do a simple series of calls to end a thread.

if (MyThread)
{
while (MyThread->Suspended())
MyThread->Resume();
MyThread->Terminate();
MyThread->WaitFor();
delete MyThread;
MyThread = NULL;
}

This will almost always guarentee a clean eradication of the thread so that it may be used again later. Also, when you create the thread:

if (!MyThread)
MyThread = new MyThread(TrueOrFalse);

Hope that helps,
Chris
 
That was pretty simple.
Don't know what I was thinking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top