Re: Unix signals in GLib



On 2010-04-30 08:53, Richard Hughes wrote:
> On 30 April 2010 14:36, Stef Walter <stef-list memberwebs com> wrote:
>> Remember that this doesn't work correctly in threaded apps, as we found
>> in gnome-keyring-daemon. You have to do the strange
>> signal-handling-thread-thing.
> 
> Could you give more details please? Thanks.

For reasons that are almost, but not entirely, clear to me you have to:

 1. Block signals you're interested in on all threads, usually done
    early on, before starting any threads. Using pthread_sigmask.
 2. Unblock those signals in a new purpose specific thread, and call
    sigwait in that thread, in a loop, handling signals as they come in.

This is partly due to the fact that signals will be delivered on random
threads in a multi-threaded app. But there's another reason I don't
completely understand, because if that was the only reason, then it
seems the writing to a socketpair should work.

Anyway, in gnome-keyring-daemon things didn't stabilize with our signal
handling until we did this.

Code here:

http://git.gnome.org/browse/gnome-keyring/tree/daemon/gkd-main.c#n285

Cheers,

Stef


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]