[libdispatch-dev] What's with this sigsuspend stuff?

DrPizza DrPizza at quiscalusmexicanus.org
Mon Jul 4 10:36:58 PDT 2011


I'm trying to understand the purpose of _dispatch_sigsuspend() [1], but for the life of me, I cannot see what it is.

To the best of my knowledge, sigsuspend() blocks a single thread (not an entire process, per POSIX [2]), suspending it until one of the signals in the sigset_t is sent to that thread.

sigsuspend() requires that the sigset_t be properly initialized (using either sigemptyset() or sigfillset()) and then, optionally, modified (using sigaddset() or sigdelset()). The behaviour is undefined if this does not occur. _dispatch_sigsuspend() does not properly initialize the sigset_t, instead passing it straight to sigsuspend(). So whatever the purpose of this function is, it probably isn't doing it properly.

But then, what is that purpose? _dispatch_sigsuspend() is sent to the normal priority, non-overcommitting queue. This is a multithreaded queue, and the block is only sent once. The function loops forever; even if the sigsuspend() returns, it gets called again immediately. So the net result is surely that one of the threads in the workqueue will just be stuck forever?

Clearly I'm missing something here; can anyone enlighten me?

Regards,

Peter


[1]: http://libdispatch.macosforge.org/trac/browser/trunk/src/queue.c#L953
[2]: http://pubs.opengroup.org/onlinepubs/007908799/xsh/sigsuspend.html



More information about the libdispatch-dev mailing list