Re: sigqueue() losing signals

From: Robert Hancock
Date: Thu Oct 30 2008 - 20:51:52 EST


James Renton wrote:
I needed to kick off a bunch of background threads and receive
notification if one failed due to fatal error. I was hoping waitpid()
would work; but found out quickly that although each thread has a pid_t;
threads and processes were not interchangeable. Without a timed
pthread_join() over multiple threads (like WIN32
WaitForMultipleObjects), I formulated a seemingly dead simple
implementation using signals. I hacked out a quick prototype to ensure
I could get the signals to work as desired.

When I ran the prototype, I experienced behavior looking very bug-like;
but I wanted to post it here in case I am misunderstanding unix signals
and just doing something silly. I am requesting for comments or
[hopefully clever] suggestions... Code follows:

For normal signals, you're not guaranteed that the signal handler will be called once for every time the signal is raised. You may get only one signal handler call for multiple events if they happen in rapid succession. Maybe if you use realtime signals it will work. But this seems like a bizarre way to accomplish the task.. better to just set some pthread condition in your threads when they exit and do a pthread_cond_timedwait on that condition in the main thread.

IMHO, in general, when signals are the answer, chances are the question is wrong..

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/