libev signal mask and thread

Marc Lehmann schmorp at
Sat Apr 28 18:56:33 CEST 2012

On Sat, Apr 28, 2012 at 06:47:31PM +0400, Konstantin Osipov <kostja at> wrote:
> > > How exactly does libev work with the process signal mask?
> Sorry, I meant the thread signal mask.

That's basically the same - posix threads only have one type of signal

> Unless I block signals in all threads but the main, the signal
> sent to a process can be delivered to any thread, and thus libev
> won't see it.

If this is the case, then this is another issue, independent of
libev. Libev does not care which thread handles the signal, it only
cares about not receiving a signal while it manipulates it's signal data

> I was wondering what would be a canonical way to do it? 

Well, your problem seems to come from another component, not libev. Libev
is fine with either way.

> A simple approach is to temporarily block signals by calling
> pthread_sigmask(), then call pthread_create(), make sure the created
> thread inherits the signal mask, and then unblock signals
> again and let libev handle them.

Blocking all signals in threads that are normally not interested in
handling them is good programming practise, and the way you describe is
the canonical way to do that (i wish glib would do that :).

It's not required for libev, though - libev doesn't know anything about
threads, and does not care about which thread handles the signal.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list