Hi Everybody;

I wrote a class that uses boost library to create thread. My thread function just do select operation for mysql database. Besides, I developed a client program to test server side, but server side gave 'segmentation error ' after fourth client request via socket.

void Thread::Start(void (*function)()){
    boost::thread th(function);
    th.join();
}

and

//my thread function
//connection part successfully works.
void tf(){

    db.ConnectDatabase();
    cout<<"db connected"<<endl;
    MYSQL_RES* result= db.Select("SELECT * FROM store");
    MYSQL_ROW row;
    while((row = mysql_fetch_row(result)) != NULL ) {
    printf("Store Name : %s\n", row[0]);
    }
    db.CloseDatabase();
    cout<<"database closed"<<endl;
}

Output
---------

Database initialize started...
Database init finished
db connected
Query : SELECT * FROM store
Store Name : Kipa
Store Name : Kipa
Store Name : Kipa
Store Name : Best Buy
database closed
db connected
Query : SELECT * FROM store
Store Name : Kipa
Store Name : Kipa
Store Name : Kipa
Store Name : Best Buy
database closed
db connected
Query : SELECT * FROM store
Store Name : Kipa
Store Name : Kipa
Store Name : Kipa
Store Name : Best Buy
database closed
db connected
Query : SELECT * FROM store
Store Name : Kipa
Store Name : Kipa
Store Name : Kipa
Store Name : Best Buy
database closed
make: *** [run] Segmentation fault

Thank you..

1. Use a debugger.
As in

gcc -g prog.c
gdb a.out

First thing to try is just letting it run, then use the 'bt' command to get a stack trace at the point it segfaults.
Then read the help to figure out how to examine variables, set breakpoints for future runs etc etc.

2. I notice a lack of error checking, particularly with regards to result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.