I am writing a multithreaded application in C ++ using Boost threads (pthread). The application spawns 100 threads, and each thread performs the following task (I write a piece of code that will be launched in each thread):
try {
driver = get_driver_instance();
con = driver->connect(SettingsClass.HostName, \
SettingsClass.UserName,SettingsClass.Password);
con->setSchema("MyDatabase");
driver->threadInit();
string dbQuery = "select A, B, C from XYZTable where D=?";
prepStmt = con->prepareStatement(dbQuery);
prepStmt->setInt(1, 1);
rSet = prepStmt->executeQuery();
delete rSet;
delete prepStmt;
if (con != NULL && !con->isClosed()) {
con -> close();
driver->threadEnd();
delete con;
}
catch (SQLException &e)
{
}
When the process starts (the application, as mentioned earlier, i.e. with 100 such threads), I attach gdb halfway and observe that more than 40% of the threads hang in the read () call. All reverse traces have mysql library functions (vio_read (), etc.), and none of them are from my code, since my code does not perform any I / O.
Can anyone please indicate why this problem occurs. Should I check my code / network or MySQL configuration? Did I use the C ++ Connectors library correctly?