我有一個C進程,正在迅速寫入MySQL數據庫〜每秒10次。此過程使用MySql C連接器。MYSQL C連接器
後約2分鐘的運行的,該過程掛起,並在系統監視器的顯示
"futex_wait_queue_me"
,並且還
"Can't initialized threads: error 11"
被打印到控制檯,我假定由C連接器庫(因爲我不打印這個)。之後寫入,連接到mysql失敗
"MySQL server has gone away".
什麼可能導致此?我只從1個線程寫入。
fyi,我正在使用庫。互斥鎖和解鎖有未來,因爲我將多線程日誌記錄。實際應用程序中的日誌記錄事件將少得多,但我試圖在這個特定的測試中儘可能強調它。
//pseudocode:
while(1)
mutexlock
connect();
mysql_query();
disconnect();
sleep(100ms);
mutexunlock
A better solution, maybe not the best
connect();
while(1)
mutexlock
if error on mysql_query();
disconnect();
connect();
sleep(100ms);
mutexunlock
//connect/disconnect functions
int DBConnector::connect()
{
if(DBConnector::m_isConnected) return 0;//already connected...
if(!mutexInitialized)
{
pthread_mutex_init(&DBLock, 0);
}
if(mysql_library_init(0, NULL, NULL))
{
LoggingUtil::logError("DBConnector.DB_connect [DB library init error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
if((mysql_init(&m_SQLHandle)) == NULL)
{
LoggingUtil::logError("DBConnector.DB_connect [DB mysql init error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
if((mysql_real_connect(&DBConnector::m_SQLHandle, host.c_str(), user.c_str(), pw.c_str(), db.c_str(), port, socket.c_str(), client_flags)) == NULL)
{
LoggingUtil::logError("DBConnector.DB_connect [DB Connect error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
DBConnector::m_isConnected = true;
return 0;
}
int DBConnector::disconnect()
{
DBConnector::m_isConnected = false;
mysql_close(&DBConnector::m_SQLHandle);
mysql_library_end();
return 0;
}
爲什麼當'mysql'處理比賽和其他相同的問題本身時使用'mutex'? – deepmax