Click to See Complete Forum and Search --> : pthread_sigmask strange behavior


shex
September 22nd, 2005, 10:48 AM
hi :)

i'm trying to print all stack traces of all my thread (in a certain process), the initiative is one of these threads.

meaning: one thread wants all traces of all his siblings.
all i found was backtraces function that prints current thread trace.

i started thinking that i could send a signal to each thread telling him to print its own trace.
the thing is i dont have their id's(don't ask y).
because i didn't find a way to get all threads ids from pthread's methods, i thought i was stuck.
but then i thought i could sent a signal to my process, first using the sigmask to block the signal, meaning that one other thread must catch it, the handler method will order him to print his trace, and recusivly send the signal again (again, block signal first) so other threads will catch the signal.

well, it didn't work, don't know why yet, thats where you come in :)
or if you have other advise to make this simple request not so complicated(print all traces)

anyway, the code doesn't work
(goes into an infi. loop inside myHandler)
void myHandler(){
sigaddset(&signal_mask, SIGINT);
pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); // <=the problem
printf("my handler was activated");
sleep(1);
kill(0, SIGINT);
}

thanks in dvance,
shex

NoHero
September 22nd, 2005, 11:04 AM
My expirience with POSIX sig's very poor but maybe this (http://www.hmug.org/man/2/pthread_sigmask.php) helps a bit.