Signal Handling in Threads[POSIX]
I have written a small program with 3 threads. All the threads have an infinite while loop in which it prints something. I have registered a SIGINT handler in main before creating any thread, in which i just do a print message & then exit(0). The main() just creates these threads and wait for them to join. the problem is that even if i press Ctrl-C, the handler is not getting called. It is called only if i keep it pressed for a few seconds. Why is this happening? Also, if i give a sleep(1) in the while loop of all the threads, the handler is getting called immediately. How this behaviour can be explained?
|