Today, there is a problem, GDB executes the program completely no problem, but the direct execution will be section error, baffled its solution, all kinds of entanglements, a variety of search engines have tried again, no fruit! Then the problem was dug out by myself.
Look at the code below:
int Tasksendcontrol () {pthread_t prov_thread[client_num];int prov[client_num]; for (int i=0; i< client_num; i++) { Prov[i] = i; if (Pthread_create (&prov_thread[i], NULL, Provtasksend, (void*) &prov[i])! = 0) { cout << " Tasksendcontrol "<< Endl;gv_alert. Insertalert (Main,1,gv_localname,gv_localip,exception_db_error, Codewhere, ""); Exit ( -1);} } return 0;} void *provtasksend (void * prov) {int provid = * (int *) Prov; C_node *tmpnode; while (1) {... Omit program more//Issued idling sleep (2);}}
Do you think there's going to be a problem? I didn't think there would be any problem at the beginning, I will be in the sub-thread in the loop set idling, the program can run normally, so I always think it is a while loop inside the program has a problem, but how can not find out!
I gdb run the time is also normal, which makes me very crash, unable to debug!
I came back to think of a paragraph error must be a pointer access problem, must be illegal.
After careful analysis, the code snippet exits when the thread is created, if the thread has not finished creating it (while the program in the while loop is more), then the temporary variable is released, so that the segment is wrong.
To modify a program:
int Tasksendcontrol () {static pthread_t prov_thread[client_num];static int prov[client_num]; for (int i=0; i< client_num; i++) { Prov[i] = i; if (Pthread_create (&prov_thread[i], NULL, Provtasksend, (void*) &prov[i])! = 0) { cout << " Tasksendcontrol "<< Endl;gv_alert. Insertalert (Main,1,gv_localname,gv_localip,exception_db_error, Codewhere, ""); Exit ( -1);} } return 0;}
Sure enough, the program runs normally!