List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:July 11 2014 3:17am
Subject:Re: Problem with attempt to share a Connection between threads
View as plain text  
On Jul 10, 2014, at 8:32 PM, Damien Kick <dkick@stripped> wrote:

>> What I don’t see are any calls to thread_start(), […]
> 
> struct Thread_guard {
>    Thread_guard() { mysqlpp::Connection::thread_start();

Sorry, I was looking at the top of my::work().  Are you sure this gets called before
my::work() does anything useful?

(Assume I know nothing about the C++11 threading features.  I’m not going to be able
to move off C++98 for years yet.)

>> […] use of ConnectionPool, […]
> 
> I didn't think that was required; is it required?

No, it would just be one way for your code to demonstrate to me that you weren’t
just hacking blindly away and expecting thread safety for free.

>> or — best of all, IMHO — binding of Connection objects to individual
> threads.
> 
> I don't know what that means "bind of Connection objects to individual
> threads”.

It means that at the top of each thread worker, create the connection in that thread, and
never use the connection outside that thread, nor pass any MySQL++ objects it creates
outside that thread.  You can pass copies of the *data* you get from the DB outside the
thread.

The idea is to prevent race conditions and lifetime problems.

http://tangentsoft.net/mysql++/doc/html/userman/threads.html#thread-conn-mgmt
Thread
Problem with attempt to share a Connection between threadsDamien Kick10 Jul 2014
  • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
    • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
      • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
        • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
          • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
            • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
              • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
                • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
              • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
                • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
                  • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014
                    • Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
                      • Re: Problem with attempt to share a Connection between threadsAdrian Cornish11 Jul 2014
  • Re: Problem with attempt to share a Connection between threadsChris Frey13 Jul 2014
Re: Problem with attempt to share a Connection between threadsDamien Kick11 Jul 2014
  • Re: Problem with attempt to share a Connection between threadsWarren Young11 Jul 2014