multithreadingwinapiterminate

Can TerminateThread() terminate GetCurrentThread()?


The docs don't say whether the result of GetCurrentThread() is a valid argument to TerminateThread(), iow: whether a thread can cancel itself.

Can it? And if yes, does TerminateThread() then return at all?


Solution

  • Yes, TerminateThread can terminate the current thread. The result of GetCurrentThread has THREAD_ALL_ACCESS rights, so that handle can be used too.

    No, TerminateThread won't return in this case.

    No, there is no reason to ever do this! Don't.