[nanomsg] Re: signal mask in posix threads

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Wed, 28 May 2014 10:10:28 +0200

-----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?

Martin

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJThZn0AAoJENTpVjxCNN9YxhkH/1a4U00VhIP41lA/m1hHfODL
NbakCd2+pXnbHdHtWMf7Ahy1bY7YYuxJSfYUrd17WvfxldL0tep8a6C6NFS0NmvW
fP2HiranABIOdf97H+vslQlQ/RPN258cSycSTuhAJoXQhbqHazutxDAX3YGKn0wU
NT1y34oXvgJ4TFRcs5aTOWiTic/jqo3LhBHmKj0Nr5ILygJKXcA/IuYKUQtNpaKm
kwmycL6M4316Mx5y93HqYoIIRyZX1kEzV+T3KLzk0e6/g8Uevk4Z3i6x4lv20PG/
mQU7i+ShEkfzbjr75mZccAngoZDfsZOBQ4jTlT2qHAfwGtsHpnYbA9FPfUnm6wM=
=y7mz
-----END PGP SIGNATURE-----

Other related posts: