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,

John Ledbetter
  • 13,557
  • 1
  • 61
  • 80
Badr
  • 10,384
  • 15
  • 70
  • 104
  • possible duplicate of [kill thread in pthread](http://stackoverflow.com/questions/2084830/kill-thread-in-pthread) – Yuval Adam May 27 '10 at 08:06
  • possible duplicate of [Terminating a thread gracefully not using TerminateThread()](http://stackoverflow.com/questions/1702172/terminating-a-thread-gracefully-not-using-terminatethread) – kennytm May 27 '10 at 08:35

1 Answers1

5

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 enter the CS with another thread.

harper
  • 13,345
  • 8
  • 56
  • 105