/* * This test program works on 32-bit Cygwin, but fails on 64-bit systems. * Running a signal handler for SIGFPE on the created POSIX thread does * not work. * * Compile with * * gcc -Wall -O0 -pthread -osyncsig_mt ./syncsig_mt.c * * Run with * * ./syncsig_mt * * Expected Result * * Program prints "signal handler running" * * Actual Result * * No output on 64-bit systems, signal handler does not run * */ #include #include #include #include static void signal_handler(int signum, siginfo_t* info, void* ucontext) { fprintf(stderr, "signal handler running\n"); // unsafe in real code! } static void* thread_start(void* arg) { int argc = *(int*)arg; /* Trigger Windows Exception for division by zero */ argc /= !argc; fprintf(stderr, "no exception generated\n"); return NULL; } int main(int argc, char* argv[]) { struct sigaction act = { .sa_sigaction = signal_handler, .sa_flags = SA_SIGINFO, }; sigemptyset(&act.sa_mask); sigaction(SIGFPE, &act, NULL); pthread_t thread; pthread_create(&thread, NULL, thread_start, &argc); pthread_join(thread, NULL); return EXIT_SUCCESS; }