my_thread_global_end threads didn't exit, error?

15,072

Solution 1

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.

Solution 2

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.

Solution 3

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
Share:
15,072
Raviprakash
Author by

Raviprakash

Started career as Mac OS System Software developer. Later became Mobile App developer. Have experience and expertise in iOS and Android Mobile app development. Curious about science. Interested in software design and architecture.

Updated on June 09, 2022

Comments

  • Raviprakash
    Raviprakash almost 2 years

    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?