简体   繁体   中英

how to exit or stop a running thread in c?

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM