We are currently exploring creating a lib we can link into our dll or executable (Windows) and came across the DllMain specialized behavior below.
DllMain sets a flag when the process is terminating
Should we reproduce this functionality? Any other thoughts on creating a lib?
Thanks,
-Josh
DllMain sets a flag when the process is terminating
volatile long g_isProcessTerminating = 0;
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_DETACH:
// A non null lpReserved parameter indicates that the process is terminating
if (lpReserved != nullptr)
{
g_isProcessTerminating = 1;
}
....
Later in ~io_scheduler I find the only use of the flag:io_scheduler::~io_scheduler()
{
if (g_isProcessTerminating != 1)
{
// Cancel pending callbacks and waits for the ones currently executing
CloseThreadpoolCleanupGroupMembers(m_cleanupGroup, TRUE, NULL);
// Release resources
CloseThreadpoolCleanupGroup(m_cleanupGroup);
DestroyThreadpoolEnvironment(&m_environ);
}
}
What is the intent of this condition? Is this purely an optimization? It appears to not block/wait while cleaning up the threadpools if the process is terminating vs being unloaded via FreeLibrary.Should we reproduce this functionality? Any other thoughts on creating a lib?
Thanks,
-Josh