Hi,
I'm using the mysqlclient_r library to access the database.
I have written some code as an interface to access the MYSQL databse and
have written the following test code to test the library.
I'm using Linux 2.4.4-4 as the platform.
I'm putting locks around my entire test case so that two threads do not
share the same connection at the same time.
as suggested earlier I have also built the library with local pthreads
i.e. --with-pthread=-pthread or --with-pthread=-lpthread
This code still is not working when compiled with libmysqlclient_r
but works with libmysqlclient.
The following is the code with places of my_init(), my_init_thread(),
and my_thread_end().
Since I'm new to using this library I would be grateful for any kind of
guidance on where I'm going wrong.
regards,
void * threadTest2(void *jl){
int *te = (int *)jl;
int t1 = (*te);
// my_thread_init();
test2(t1);
my_thread_end();
pthread_exit((void *)NULL);
}
void startThreadsTest2(){
Init();
my_init();
int ThreadNum[MAXTHREADS];
int i;
for(i = 0; i < MAXTHREADS; i++)
ThreadNum[i] = (i + 1);
pthread_t threads[MAXTHREADS];
for(i = 0; i < MAXTHREADS; i++){
my_thread_init();
pthread_create(&threads[i], NULL, threadTest2, (void*)
(ThreadNum +i));
}
for(i = MAXTHREADS - 1; i >=0 ; i--)
pthread_join(threads[i], NULL);
cout << endl << endl;
for(i = 0; i < MAXTHREADS; i++)
cout << "SuccessQuery[" << (i + 1) << "]: " << SUCCESS_QUERY[i]
<<
endl;
cout << endl << endl;
for(i = 0; i < MAXTHREADS; i++)
cout << "failureQuery[" << (i + 1) << "]: " <<
FAILURE_QUERY[i] <<
endl;
}
void test2(int l = 0 ){
//LOCK
pthread_mutex_lock(&lockmutex);
FASDBConnection conn1;
conn1.Connect("lithium.ini.cmu.edu","shivam_test","shivam","shivam_pass");
if(conn1.isConnected())
cout << "Success Connection" << endl;
else
cout << "Failed Connection" << endl;
for(int i = 0; i < 1000; i++){
string query = "SELECT * from STUDENTS ";
FASDBStatement *r = conn1.createStatement();
FASDBResult rr;
rr = r->ExecuteQuery(query);
int num = rr.getNumRows();
if(num == 0){
cout << "Query failed number: " << (i+1);
if(l != 0){
// FAILURE_QUERY[l-1]++;
cout << " Failure Thread Num: " << l;
}
cout << endl;
delete r;
continue;
}
// SUCCESS_QUERY[l-1]++;
cout << "QUERY NO." << i << endl;
while(rr.nextRow()){
FASDBRow row = rr.getCurrentRow();
cout << setw(10) << row.getString(0);
cout << setw(10) << row.getString(1);
cout << setw(10) << row.getInteger(2) << endl;
}
cout << "Index : " << (i+1) << "ThreadID: " << l << endl;
delete r;
}
conn1.Close();
//UNLOCK
pthread_mutex_unlock(&lockmutex);
}
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php