Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 30.6Mb
PDF (A4) - 30.8Mb
PDF (RPM) - 30.1Mb
EPUB - 7.7Mb
HTML Download (TGZ) - 7.5Mb
HTML Download (Zip) - 7.5Mb
HTML Download (RPM) - 6.4Mb
Eclipse Doc Plugin (TGZ) - 8.2Mb
Eclipse Doc Plugin (Zip) - 10.1Mb
Man Pages (TGZ) - 200.3Kb
Man Pages (Zip) - 311.6Kb
Info (Gzip) - 2.9Mb
Info (Zip) - 2.9Mb
Excerpts from this Manual

23.8.12.3 mysql_thread_init()

my_bool mysql_thread_init(void)

Description

This function must be called early within each created thread to initialize thread-specific variables. However, you may not necessarily need to invoke it explicitly: mysql_thread_init() is automatically called by my_init(), which itself is automatically called by mysql_init(), mysql_library_init(), mysql_server_init(), and mysql_connect(). If you invoke any of those functions, mysql_thread_init() will be called for you.

Return Values

Zero for success. Nonzero if an error occurred.


User Comments
  Posted by Armin Schöffmann on March 6, 2005
According to dll.c:
Within win32, LibMain calls mysql_thread_init() and mysql_thread_end() automatically for each newly created thread after the lib has been loaded.
Therefor it shouldn't be necessary to call these functions again. As I said, only for win32 and only if we use the dynamic library.
  Posted by Gordon Eldest on August 5, 2012
mysql_thread_init() did crash on my machine, did investigate as mysql_init() is doing it for me.

MORE IMPORTANT remember that:

1) A new thread NEED a SPECIFIC new MYSQL* handle.
So need a call mysql_init() WITHIN your new thread.
(libmysql work badly with exotic error if you use MYSQL* handle from another thread)

Also check
if (!mysql_thread_safe()) {
m_strErrorMessage = "Thread Safe OFF: ";
ASSERT(0); // Major problem: libmysqlcompiled ThreadSafe?
}

2) you NEED EXPLICTELY to call mysql_thread_end() !!
Do it once you release mysql_close(MYSQL*..)
Or you will get Handle leak !!
(which is as bad as memory leak!)

So no bugs but if multithread carefully read API doc

For reference our destructor of our generci MySqL handler object.

HCMySQL::~HCMySQL()
{
if (m_poMySQLHandle && m_bConnection ){ // Did we use it?
mysql_close(m_poMySQLHandle) ;
mysql_thread_end(); //or 3 Handle leak!
}
if (--s_ref==0){ // incremented in ::Connect
mysql_library_end();
}
}


Sign Up Login You must be logged in to post a comment.