I successfully use libdbi in production with MySQL and Postgres servers in
multithreading, but by multithreading I mean that I am using one connection
per thread, and a variable pool of threads, with connections to MySQL and
Postgres on the same libdbi instance. A server going down does not cause any
issue.

However, you might be encountering an issue with the dbi_conn_error, which
last time I checked was not thread safe, because it is sharing a static char
* between all connections! I guess I should have filed a bug.
Here's how I get around it:

        // dbi_conn_error is not thread safe, it uses a static char *
        // internally which could be freed twice if the function is not
locked
        boost::mutex::scoped_lock lock(sErrorMutex);
        const char *dbError = NULL;
        int errNum = dbi_conn_error(mDbConn, &dbError);
        Logger::logX( LOG_WARNING, "1504 - Failed to connect to DB with
connection string \"%s\", reason: %d - %s",
dbAccess->getConnection().c_str(), errNum, dbError );


Anyway, why don't you "gdb" your crash, it will give you a better hint of
where the problem actually is.

Regards,
Emmanuel.

On Thu, Aug 19, 2010 at 10:24 AM, Markus Hoenicka <
markus.hoeni...@mhoenicka.de> wrote:

> Shaofeng Yang <breath...@gmail.com> was heard to say:
>
> > Greeting,
> >
> > I am working on a thread pool with libdbi and libdbi-driver-mysql. i saw
> a
> > problem that program crashes if mysql server goes away for one thread. i
> am
> > using the thread safe version of libdbi and the design of my thread pool
> > doesn't have problems.  The problem comes out from libdbi mysql driver,
> > which  is compiled against libmysqlclient not libmysqlclient_r by
> default. I
> > am just wondering what i should do to make libdbi mysql driver
> thread-safe.
> > Can I just change the makefile.am to use -lmysqlclient_r instead
> > of -lmysqlclient? Is dbd_mysql.c thread-safe?
>
> Hi,
>
> I assume you connect to the server before starting your threads. Would
> it be possible to use the new interface (available in CVS and in the
> eventually to be released libdbi version 0.9) which allows to manage
> independent instances of libdbi in a single process? You could use
> that to connect to the server in each thread separately, so if one of
> them goes away it should not affect the other instances.
>
> I'm not familiar with thread-safe programming, so I have no idea if
> libdbi is currently thread-safe. Someone more familiar with this issue
> should speak up.
>
> As for libmysqlclient and libmysqlclient_r: if these libraries use the
> same API, I guess you can simply change Makefile.am to use the latter.
> If that works, we should probably make this a configurable build option.
>
> regards,
> Markus
>
>
>
> --
> Markus Hoenicka
> http://www.mhoenicka.de
> AQ score 38
>
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Libdbi-drivers-devel mailing list
> Libdbi-drivers-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel
>
------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Libdbi-drivers-devel mailing list
Libdbi-drivers-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel

Reply via email to