Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Creating a Casablanca lib and understanding the io_scheduler destructor

$
0
0
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
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

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>