请查看下面的代码段//在 DLL项目中单个.cpp单元下定义的这些代码块
static std::thread sendMessageThread; // define as local static to cpp
bool callFunction()
{
/// Some simple code without spawning any thread or fibers
}
void WINAPI OnEngineStart()
{
sendMessageThread = std::thread(callFunction);
};
BOOL WINAPI DllMain(HINSTANCE hDll, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
if (sendMessageThread.joinable())
{
sendMessageThread.join(); // is this safe?
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
};
如果加载DLL的进程调用 OnEngineStart 函数,那么只要它卸载DLL(使用 FreeLibrary WinAPI函数), 会等到 sendMessageThread 结束吗?并继续DLL卸载程序?