mysql cppconn and pthreads

Hi folks,

There's something that's just not clear to me about the proper way to use the mysql cppconn library for making multiple (let's say 10 or less) concurrent writes to a mysql database.

What I am trying to accomplish is that my main function will use pthreads to run up to 10 simultaneous threads of a worker function, and this worker function needs to insert some data into a mysql database.

looking here
http://mysql-connector-cplus-pplus-p.sourcearchive.com/documentation/1.1.0-1/pthreads_8cpp-source.html
the example shows how to use the mysqlcppconn library in synergy with pthreads.

***However*** the example code is such that the main thread spawns only one separate worker thread that deals with mysql... here the main thread simply waits for that one thread to complete. this is not what i need.

So this example (which is also included with the latest cppconn package) doesn't make it clear how to have multiple worker threads.

In particular, what make me doubt whether the example code is suitable for multiple concurrent threads is the following:
1
2
driver = sql::mysql::get_driver_instance();
con.reset(driver->connect(url, user, pass));

This is placed in MAIN, and it would seem to me that each thread would want its own instance of the driver, and connection, wouldn't it? or... if these lines are instead supposed to be placed inside a worker thread, does it need a mutex just during the get_driver_instance and connection stages? what about when executing a query?

If anyone can give some hints, and/or post some example code how to setup mysqlcppconn for concurrent threads to make concurrent queries I would be most appreciative.
Thanks,
Brian
Last edited on
bumping up for current visibility because i moved the post between threads.
Topic archived. No new replies allowed.