Is there a way to get a notification that a thread no longer runs (has returned) in your application?
I know this is possible in kernel mode (using PsSetCreateThreadNotifyRoutine), but is there a way to know this from user mode, using only Win32 API ?
The problem is that I can’t control the code in the thread, because my module is part of a library. Making a driver to monitor the system would not be too hard, but it’s annoying for the users to install a driver even for a basic application that uses my library.
My code uses TLS storage, and under Linux/Unix pthread_key_create can take a pointer to a function that is called when the thread is destroyed. But TlsAlloc (Windows) has nothing like this…
Thanks in advance!
Depends on what kind of libraray you have. For a DLL could handle the thread termination in your DllMain (
DLL_THREAD_DETACH). The MSDN states that this is the best place to deal with TLS Resources.Keep in mind that this callback is only calld for a thread exiting cleanly (not by e.g
TerminateThread()).