There is a problem with thread cancellation, stack unwinding and shared libraries. (Tested on Ubuntu 8.10 with gcc 4.3.2-1ubuntu12, libc-2.8.90.so and Ubuntu 7.10.) If pthread_cancel is called in the library, a segmentation fault occurs. For static linkage the problem does not occur and the thread is canceled as expected. In the attachment you can find a demo application reproducing the problem. It consists of an Makefile and the source files: main.cpp thread_test_lib.h - library interface thread_test_lib.cpp - library source If you invoke make the shared library libthread_test_lib.so and the application thread_test are built. Make also generates thread_test_static which is the same application, but statically linked. The library provides the functions thread_setup() to create an internal task and thread_cleanup() to cancel the task. When thread_test is executed a segmentation fault occurs: ./thread_test thread_setup() run_thread::task() started thread_cleanup() Segmentation fault (core dumped) According to the core dump the segmentation fault is inside task(). It can be observed that no segmentation fault occurs for one of the following conditions: - ./thread_test_static is called instead of ./thread_test - the line "std::string s..." inside task() (see thread_test_lib.cpp) is commented out - usleep() in task() is replaced by sleep() or pthread_testcancel - usleep() in task() is called indirectly via a wrapper function
Created attachment 4368 [details] short application to show the problem
I see no problem. The program terminates normally. Report this to your distribution maker.