Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my_thread_global_end threads didn't exit, error?

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?

like image 871
Raviprakash Avatar asked Jan 15 '10 12:01

Raviprakash


3 Answers

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.

like image 83
Raviprakash Avatar answered Oct 07 '22 02:10

Raviprakash


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.

like image 4
JojOatXGME Avatar answered Oct 07 '22 04:10

JojOatXGME


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
like image 1
Shaun A. Avatar answered Oct 07 '22 02:10

Shaun A.