I have created a VC++ thread using CreateThread() function,I want to know how to terminate the created thread from an outside function.
e.g.
HANDLE Handle_Of_Thread_1 = CreateThread( NULL, 0,Thread_no_1, &Data_Of_Thread_1, 0, NULL);
void Thread_no_1
{
}
My question is how to terminate the Thread I have created from an outside function.
There is a
TerminateThreadfunction that you can use, but it should normally be reserved for dire emergencies. When you use it, the thread gets no chance to clean up after itself, which can easily leave the entire process in an unstable state.Most of the time, you want to send some sort of signal to the thread to tell it to exit normally, releasing resources, etc., in the process. This can be done in several ways, such as setting an event it checks periodically.