I get a segmentation error when joining a child thread, and I have exhausted all the options I could come up with for debugging by looking at the Stack-overflow and the rest of the Internet! :) I will be as much as possible. The code is written in C ++ and compiled with GNU GCC on OSX 10.6.8. I contacted the pthread library using the -pthread option. I also tried '-lphtread'. No difference.
I use the following global variables:
pthread_t gTid;
pthread_attr_t gAttr;
int gExitThread = 0;
I create a child thread from my main thread of execution:
err = pthread_attr_init(&gAttr);
if (err)
{
throw CONTROLLER_THREAD_ERROR;
}
err = pthread_attr_setdetachstate(&gAttr, PTHREAD_CREATE_JOINABLE);
if (err)
{
throw CONTROLLER_THREAD_ERROR;
}
err = pthread_create(&gTid,&gAttr,threadHandler,NULL);
if (err)
{
throw CONTROLLER_THREAD_ERROR;
}
Inside "threadHandler", I have the following execution loop using the base API:
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, RUN_LOOP_TIMEOUT, false);
while (result == kCFRunLoopRunTimedOut)
{
if (gExitThread) break;
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, RUN_LOOP_TIMEOUT, false);
}
gExitThread , ,
. RUN_LOOP_TIMEOUT 2 ( ).
:
int err = 0;
void* exitValue = NULL;
printf("Stopping controller thread...\n");
gExitThread = 1;
err = pthread_join(gTid, &exitValue);
if (err)
{
displayError2(err);
throw CONTROLLER_THREAD_ERROR;
}
err = pthread_attr_destroy(&gAttr);
if (err)
{
throw CONTROLLER_THREAD_ERROR;
}
"pthread_join" . , "pthread_join" , , "usleep (2000000)"!
"pthread_join" "usleep".
pthread_join:
#0 0x00007fff8343aa6a in __semwait_signal ()
#1 0x00007fff83461896 in pthread_join ()
#2 0x000000010000179d in Controller::cleanup () at src/native/osx/controllers.cpp:335
#3 0x0000000100008e51 in ControllersTest::performTest (this=0x100211bf0) at unittests/src/controllers_test.cpp:70
#4 0x000000010000e5b9 in main (argc=2, argv=0x7fff5fbff980) at unittests/src/verify.cpp:34
USleep (2000000):
#0 0x00007fff8343aa6a in __semwait_signal ()
#1 0x00007fff8343a8f9 in nanosleep ()
#2 0x00007fff8343a863 in usleep ()
#3 0x000000010000177b in Controller::cleanup () at src/native/osx/controllers.cpp:335
#4 0x0000000100008e3d in ControllersTest::performTest (this=0x100211bf0) at unittests/src/controllers_test.cpp:70
#5 0x000000010000e5a5 in main (argc=2, argv=0x7fff5fbff980) at unittests/src/verify.cpp:34
.