You are not logged in.
Pages: 1
Hi ALL,
I have written a pthread application having two threads and one main thread. I want to register a SIGINT signal such that when I press ctr+C the programs Thread1 should send "hi" message, Thread2 should send "bye" message and then program should be terminated. I know if I register a signal handler in my main thread, then only one thread will listen that but not all.
In sort I want to register different SIGINIT signal handlers per thread basis so that each thread performs its task before entire program terminates.
Thanks...
Offline
It can't really be done... Signals and handlers are per-process, not per-thread... You might be able to pull something off using a single handler function and something else like pthread_getspecific() to allow for per-thread customized behavior... But, I think you'll find that when hit with the SIGINT, just one of the two threads, basically at random, will actually handle the signal, not both of them... You'd be best off just picking one of them to handle it and have the other block it, then that should ensure it's always the one hit with the signal; then, have the handler trigger the other thread's behavior via some other method, like pthread_cond_signal() or pthread_kill() with some other signal like SIGUSR1 or something...
Offline
Pages: 1