gcc-4.7: 'terminate called without an active exception' after unblocking in pending signal handler with pthread_exit
Hello!
I have strange behaviour for this simple code (compiled with gcc test.cpp -
lpthread -o test):
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void *thread_proc(void *arg)
{
sigset_t sigs;
sigemptyset(&sigs);
sigaddset(&sigs, SIGTERM);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
fprintf(stderr, "start thread\n");
sleep(3);
fprintf(stderr, "stop thread\n");
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
}
void thread_signal(int signum)
{
pthread_exit(0);
}
int main(int argc, char **argv)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = thread_signal;
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, 0);
pthread_t thread;
pthread_create(&thread, NULL, thread_proc, NULL);
sleep(1);
fprintf(stderr, "kill thread\n");
pthread_kill(thread, SIGTERM);
fprintf(stderr, "join thread\n");
pthread_join(thread, NULL);
return 0;
}
This sample produce 'terminate called without an active exception' exception
after pthread_exit(0).
For gcc 4.6, 4.4 its works fine. With -fno-exceptions flag its works. When i
compile this as c code (gcc test.c -lpthread -o test) its works also fine.
Thanks.
Reply to: