views:

88

answers:

1

i am using Win32 API.

i have a thread in c and want to terminate it from out side the thread so can't use exitthread()

i can't use any wait options cause i have to kill this thread and start it again in very short time.

need help,

+3  A: 

You can thermiate the thread using TerminateThread using the thread handle you got from CreateThread. see http://msdn.microsoft.com/en-us/library/ms686717(VS.85).aspx

Please note the warning in the MSDN site. Terminating a thread is dangerous.

Consider that the thread can have resources allocated, that will not released when you terminate it as you describe. example: if the thread has entered a critical section and is terminated before leaving, you won't be able to anter the CS with another thread.

harper