-
-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows 动态库中使用coost日志库导致程序不能正常退出 #294
Comments
试试在 |
我测了下,调用log::exit()是可以正常退出的. 但是这个方案有个问题,我这里实现的是一个插件,插件使用了coost的日志功能.主程序是其他公司的产品,没有源代码. |
|
这个方案不可行,主程序是国外公司的产品,全世界有很多开发者在上面做二次开发,不会单独针对我这个插件做修改.有没有其他的方案,我这里修改就可以解决这个问题? |
析构函数里面调用也不行. |
程序退出时卡住应该与之前遇到的一个坑是一样的: windows dll动态库卸载时,线程的运行时先被卸载(当时查到的资料好像是这样,没记错的话),导致线程失去作用、无法被唤醒,dll中等待线程退出的代码将永远无法响应(coost/log中是程序退出时等待写日志的线程退出,调用log::exit()会退出该线程)。 这样就能解释,为什么在调用 windows上使用动态库很容易踩到这个坑,比较安全的做法是在 dll 卸载前退出所有线程。 后续可能增加一些探测性代码,若线程长时间没有反应,就不再等待 |
好的,感谢回复.有时间的话我也研究下这个问题. |
Windows10 64 位环境
生成一个dll,导出如下函数
DLLLOG_API void LogMessage()
{
LOG << "111";
}
生成一个exe,代码如下
typedef void (LogMessageFun)();
int main(int argc, wchar_t argv[])
{
HINSTANCE hinst = LoadLibrary(L"DllLog.dll");
if (hinst != nullptr)
{
LogMessageFun pLog = (LogMessageFun)GetProcAddress(hinst, "LogMessage");
}
程序不能正常退出.
The text was updated successfully, but these errors were encountered: