std::thread cause deadlock in DLLMain

前端 未结 4 974
无人共我
无人共我 2020-12-28 11:14

So, this is what I\'m talking about: std is complex.

In VS2013 this simple program will cause a deadlock.

#include 
#include 

        
4条回答
  •  时光取名叫无心
    2020-12-28 11:19

    Use detach() member function to fix the crash. Example:

    void Hook_Init();
    
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    {
        switch (fdwReason)
        {
        case DLL_PROCESS_ATTACH:
            {
                std::thread hookthread(Hook_Init);
                hookthread.detach();
                break;
            }
        }
        return TRUE;
    }
    
    void Hook_Init()
    {
        // Code
    }
    

提交回复
热议问题