List:MySQL++« Previous MessageNext Message »
From:dan g. Date:March 5 2009 8:20pm
Subject:Re: Confirmation about thread un-safety/safety
View as plain text  

Just an FYI, i have written a server that has uses 3 sql connection objects for internal
use, and every connection to the server spawns 2 other threads each with their own sql
connection.

I had terrible problems sharing a connection and then came upon the documentation that
said not to do this.. just create a new connection for each thread.  I have not yet found
a time where i need to actually share a single connection for any reason, though ymmv.




----- Original Message ----
From: Jim Wallace <jwallace@stripped>
To: plusplus@stripped
Sent: Thursday, March 5, 2009 9:45:54 AM
Subject: RE: Confirmation about thread un-safety/safety

Thanks for the reply. Just to confirm, from reading the link, if I use
store/store_next, I can give the StoreQueryResult to another thread
since the first is finished consuming the results and the entire result
set is in the StoreQueryResult.  (Looking at the code, that looks safe
since I'm just calling vector::at())

btw. As your pages says, using a connection on multiple threads is
dangerous.  We had a nasty bug where a Python script running in our app
passed a MySQL connection to different threads and would cause random
crashes.

-----Original Message-----
From: Warren Young [mailto:mysqlpp@stripped] 
Sent: Thursday, March 05, 2009 10:52 AM
To: MySQL++ Mailing List
Subject: Re: Confirmation about thread un-safety/safety

Jim Wallace wrote:
> I know you can't use the same connection object on different threads.

I don't think that's true, as stated.  What you can't do is use a single

connection object for two different queries at once.  This issue really 
has nothing to do with threads:

http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#concurrent
queries

Threads just make it harder to avoid running into this limitation.

> It looks like I can 't do query.store() on one thread and
> query.store_next() on another since it calls
> conn_->driver()->next_result();

Did you try it and find that it fails, or are you just avoiding it 
because you think it won't work?  If the latter, try it anyway.

Obviously due to the simultaneous query issue, you do have to avoid 
making another query on that connection until the second thread has 
finished consuming the results.  If you were hoping to avoid this, 
perhaps so you could have one thread processing results while another 
starts new queries, then you do indeed need at least two Connections.

-- 
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus?unsub=1



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=1
Thread
Confirmation about thread un-safety/safetyJim Wallace5 Mar
  • Re: Confirmation about thread un-safety/safetyWarren Young5 Mar
    • RE: Confirmation about thread un-safety/safetyJim Wallace5 Mar
      • Re: Confirmation about thread un-safety/safetyWarren Young5 Mar
      • Re: Confirmation about thread un-safety/safetydan g.5 Mar