July 27th, 2018

Is the Terminate­Thread function synchronous?

A customer wanted to know whether the Terminate­Thread function was synchronous. In other words, does the Terminate­Thread function wait until the target thread has definitely terminated before returning?

No. The Terminate­Thread function queues a termination to the target thread but does not wait for confirmation that the termination has occurred.

If you want to wait until the target thread has definitely terminated, wait for the thread object to become singnaled, say by calling Wait­For­Single­Object.

But please, stop calling Terminate­Thread. There are no valid use cases for it. Any time you call it, you will corrupt the target process, so you may as well just terminate the entire process and be done with it.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.