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.
Error in my_thread_global_end(): 1 threads didn't exit
After googling I found that mysql thread isn't exiting. Is there a method in c++ wrapper to do cleanup?
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.
If you use MySQL Connector/C++ with threads, you have to encapsulate your mysql-part within sql::Driver::threadInit()
and 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
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.
When using C++/connector, do the equivalent:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With