Hi Martin, On Wed, May 28, 2014 at 11:10 AM, Martin Sustrik <sustrik@xxxxxxxxxx> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 28/05/14 03:44, Achille Roussel wrote: >> Hi everyone, I have a question on nanomsg implementation, I think >> there may be a race conditions in the code. >> >> In src/utils/thread_posix.inc, pthread_sigmask is called at the >> beginning of the thread routine (nn_thread_main_routine), this >> means there’s a small amount of instructions where the thread could >> potentially be interrupted by an asynchronous signal… if the >> program isn’t expecting this to happen that could lead it to miss >> some signals, or worse, get killed if some default signal handlers >> get called by the worker thread instead of being handled in another >> way by the program itself (epoll / kevent / sigwait… ). A way to >> solve that would be to move the call to pthread_sigmask in before >> pthread_create, because the new thread inherits a the signal mask >> of its parent, then restore the previous signal mask after the >> call, please let me know what you think about this. > > Wouln't that just trade one synchronisation issue for another? I.e. > the main thread could lose some signals while it has signals disabled? > I think they are not lost: A signal may be blocked, which means that it will not be delivered until it is later unblocked. Between the time when it is generated and when it is delivered a signal is said to be pending. -- Paul