Tim Murison wrote:
> Hi all,
>
> First off, I'm new to multi-threaded programming, so please go easy on
> me!
>
> I am experiencing some odd problems when increasing load on a
> multi-threaded server. The problem looks like the server going into
> deadlock, but I don't think that is possible.
>
> I want to be able to have multiple readers, one writer style DB access
> using mysql++. Currently I create a connection per thread, and protect
> the queries with a pthread_rwlock_t. Obviously, only write queries get
> solo access, read queries have to share.
>
> I have read that other users have had success with multi-threaded
> access, but it is not clear to me whether they have been able to achieve
> multiple readers, one writer access.
>
> Thanks in advance...
>
> -Tim
>
>
I've had success in using mysql++ with threads under Redhat Linux.
1) One Connection Object per thread. Anything else and I just get
problems.
2) You have to link using -mysqlclient_r instead of -lmysqlclient to
ensure you get the thread-safe mysql library.
3) You have to modify MySQL++'s makefile or configure.in to ensure
you get a thread-safe MySQL++ library. This varies per platform and per
compiler, so it's difficult to actually fix properly for the
distribution. Me, I just go into the Makefile and add -pthread to the
gcc options (which is what's required under most linux distributions for
gcc).
I have had success using 3 threads -- 1 that does read/write and 2 that
write exclusively to one table each (that the other threads do not write
to).
Almost all of the problems I have run into have been primarily related
to memory allocation in the gcc STL implementation, and step 2 is
what fixed that for me.