c++ - Why does DLL_THREAD_DETACH happen twice? -


i learning com. wrote simple com component in dll , registered in registry. created simple client , tried use com component. don't understand dllmain behaviour (i read this also).

extern "c" bool winapi dllmain(   _in_ hinstance hinstdll,   _in_ dword     fdwreason,   _in_ lpvoid    lpvreserved){   pdll = hinstdll;   if (dll_process_attach == fdwreason){     trace("dllmain(): dll_process_attach");   }   else if (dll_thread_attach == fdwreason){     trace("dllmain(): dll_thread_attach");   }   else if (dll_process_detach == fdwreason){     trace("dllmain(): dll_process_detach");   }   else if (dll_thread_detach == fdwreason){     trace("dllmain(): dll_thread_detach");   }   else{     trace("dllmain(): unknown variant...");   }   return true; } 

i expected each dll_process_attach 1 dll_process_detach called , each dll_thread_attach 1 dll_thread_detach called (if exception doesn't happen).

but see single dll_process_attach there 2 dll_thread_detach:

enter image description here

why happen?

about dll_thread_attach :

note dll's entry-point function called value threads created after dll loaded process. when dll loaded using loadlibrary, existing threads not call entry-point function of newly loaded dll.

there no relation between number of dll_thread_attach , dll_thread_detach. it's loading , creation time. when thread created while dll loaded, dll_thread_attach called. when thread exits while dll loaded, dll_thread_detach called. thread never preempted dll, thread calls can happen @ creation , end of thread.

in case, log says didn't create thread after loading dll, 2 thread exited before unloading dll.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -