List:Internals« Previous MessageNext Message »
From:Dhammika Pathirana Date:June 28 2007 1:50am
Subject:Re: Is mysql_real_connect thread safe?
View as plain text  
On 6/27/07, Guilhem Bichot <guilhem@stripped> wrote:
> Hello,
>
> On Wed, Jun 27, 2007 at 10:27:18AM -0700, Dhammika Pathirana wrote:
> > I'm working on a multi-threaded daemon written in C/C++ for FreeBSD.
> > This daemon uses libmysqlclient_r.so.15 to query a mysql db. Both
> > libmysqlclient_r and the daemon are compiled with -lpthread and all
> > threads are initialized with mysql_init.
> > If I startup this daemon process at system bootup (through rc.d) then
> > I get the following core, but it seems to work fine if I start it
> > manually (after system bootup). Would really appreciate any help on
> > this.
> >
> > #0  0x2846926f in pthread_testcancel () from /usr/lib/libpthread.so.1
> > (gdb) bt
> > #0  0x2846926f in pthread_testcancel () from /usr/lib/libpthread.so.1
> > #1  0x28461856 in pthread_mutexattr_init () from /usr/lib/libpthread.so.1
> > #2  0x00000000 in ?? ()
>
> http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html
> says:
>
>  To get things to work smoothly you have to do the following:
>
>    1. Call mysql_library_init() before any other MySQL functions. It
> is not thread-safe, so call it before threads are created, or protect
> the call with a mutex.
>    2. Arrange for mysql_thread_init() to be called early in the thread
> handler before calling any MySQL function. If you call mysql_init() or
> mysql_connect(), they will call mysql_thread_init() for you.
>    3. In the thread, call mysql_thread_end() before calling
> pthread_exit(). This frees the memory used by MySQL thread-specific
> variables.
>
> From what you are saying you already have done 2); but do you also
> have 1) and 3) ?
>


mysql_library_init() solved my crash. I should've followed the recipe.

Thanks a lot

Dhammika
Thread
Is mysql_real_connect thread safe?Dhammika Pathirana27 Jun
  • Re: Is mysql_real_connect thread safe?Guilhem Bichot27 Jun
    • Re: Is mysql_real_connect thread safe?Dhammika Pathirana28 Jun
  • Re: Is mysql_real_connect thread safe?Konstantin Osipov28 Jun