macos my_thread_global_end 线程没有退出,错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2071449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
my_thread_global_end threads didn't exit, error?
提问by Raviprakash
I am using MySQL c++ connector (1.0.5) , recently I moved get_driver_instance() and connect() methods to secondary thread then I am getting below error.
我正在使用 MySQL c++ 连接器 (1.0.5) ,最近我将 get_driver_instance() 和 connect() 方法移动到辅助线程然后我得到以下错误。
Error in my_thread_global_end(): 1 threads didn't exit
my_thread_global_end() 中的错误:1 个线程未退出
After googling I found that mysql thread isn't exiting. Is there a method in c++ wrapper to do cleanup?
谷歌搜索后,我发现 mysql 线程没有退出。c++ 包装器中是否有一种方法可以进行清理?
回答by Raviprakash
After googling I came to know that mysql_thread_end() will solve the problem. Any way I was linking against libmysqlclient.a so included mysql.h file and called mysql_thread_end before exiting secondary thread, now the problem is solved.
谷歌搜索后我才知道mysql_thread_end() 可以解决问题。我以任何方式链接 libmysqlclient.a 所以包含 mysql.h 文件并在退出辅助线程之前调用 mysql_thread_end ,现在问题解决了。
回答by JojOatXGME
If you use MySQL Connector/C++with threads, you have to encapsulate your mysql-part within sql::Driver::threadInit()
and sql::Driver::threadEnd()
.
如果您将MySQL Connector/C++与线程一起使用,则必须将 mysql-part 封装在sql::Driver::threadInit()
和 中sql::Driver::threadEnd()
。
I have found another similar question here.
我在这里找到了另一个类似的问题。
Before you use any other function of the connector inside a thread, you can write something like
在线程内使用连接器的任何其他功能之前,您可以编写类似
sql::Driver *driver = get_driver_instance(); // should be synchronized
driver->threadInit();
And before the thread stops but after all other mysql-stuff, you can write somethink like
在线程停止之前但在所有其他 mysql 东西之后,你可以写一些像
driver->threadEnd();
It also seems that get_driver_instance()
is not thread safe. I get segmentation faults sometimes if I do not synchronize it. In my case I had a segmentation fault while initialization in circa one of two tests. Since I'm synchronizing the call to get_driver_instance()
, I did not have a segmentation fault right now.
这似乎get_driver_instance()
也不是线程安全的。如果我不同步它,我有时会遇到分段错误。在我的情况下,我在大约两个测试之一中初始化时遇到了分段错误。由于我正在同步对 的调用get_driver_instance()
,因此我现在没有出现分段错误。
回答by Shaun A.
When using C++/connector, do the equivalent:
使用 C++/connector 时,请执行等效操作:
sql::Driver* driver = get_driver_instance();
:
:
driver->threadEnd(); // must be done or sql thread leaks on app exit with:
// Error in my_thread_global_end(): 1 threads didn't exit