After excellently quick correction of pthread_kill when the argument signal is zero (by cgf), I have found another problem related to signal handling. The code in attachment demonstrates it ( because of pthread_kill, it must be run with cygwin1-20080213.dll and newer ). It seams that signal handlers for signals like SIGSEGV, SIGFPE are called only once, and the default handler is called for the second time the signal occures in the process. I'm not sure if the example is reasonable (e.g. pthread_exit in signal handler...), but works as expected on linux.
Output from the example compiled and run in linux: Starting SIGSEGV1... tid1=b7f1abb0 Sigaction success, errno = 0 Join1 ---> Result: 0, xx=8 Ret. value ---> Result: 8, xx=8 Good thread create ---> Result: 0, xx=8 Starting SIGSEGV2... tid2=b7519bb0 Sigaction success, errno = 0 <--------------------------- this is the end in cygwin (crash info message)------------ xx=9 Join2 ---> Result: 0, xx=9 Ret. value ---> Result: 9, xx=9
#include <signal.h> #include <pthread.h> #include <errno.h> volatile static int xx=7; void SHandler(int sig) { xx++; pthread_exit((void*)xx); return; } void* Thread1(void *arg) { struct sigaction actions; int *a=0; memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); sigaddset(&actions.sa_mask, SIGSEGV); sleep(1); actions.sa_handler = SHandler; actions.sa_flags = 0; if (sigaction(SIGSEGV,&actions, NULL)) printf("Sigaction ERROR !!!, errno = %d\n", errno); else printf("Sigaction success, errno = %d\n", errno); sleep(5); // induce SIGSEGV... *a=5; } void* OKThread(void *arg) { sleep(30); } static void printrc( char *name, int rc) { printf("%-20s ---> Result: %d, xx=%d\n", name, rc, xx); } int main() { pthread_t tid,tid2; int rc; printf("Starting SIGSEGV1...\n"); pthread_create(&tid, NULL, Thread1, (void*)1); printf("tid1=%x\n", tid); while (pthread_kill(tid, 0) !=ESRCH) sleep(1); printrc("Join1",pthread_join(tid,(void**)&rc)); printrc("Ret. value", rc); printrc("Good thread create",pthread_create(&tid, NULL, OKThread, NULL)); printf("Starting SIGSEGV2...\n"); pthread_create(&tid2, NULL, Thread1, (void*)2); printf("tid2=%x\n", tid2); while (pthread_kill(tid2, 0) !=ESRCH) sleep(1); printf("xx=%d\n",xx); printrc("Join2",pthread_join(tid2,(void**)&rc)); printrc("Ret. value", rc); return 0; }
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/