From: Francis Dupont Date: Tue, 22 Sep 2015 14:58:44 +0000 (+0200) Subject: [4065] New threads got all signals blocked X-Git-Tag: trac4074_base~26^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=720abaa70dd72ab8a413f95381b3443fb00f820a;p=thirdparty%2Fkea.git [4065] New threads got all signals blocked --- diff --git a/src/lib/util/threads/thread.cc b/src/lib/util/threads/thread.cc index 4ec90fdcac..568f6f8e2e 100644 --- a/src/lib/util/threads/thread.cc +++ b/src/lib/util/threads/thread.cc @@ -21,7 +21,9 @@ #include #include +#include +#include #include using std::string; @@ -33,6 +35,30 @@ namespace isc { namespace util { namespace thread { +namespace { + +// Signal blocker class. +class Blocker : boost::noncopyable { +public: + // Constructor blocks all signals + Blocker() { + sigset_t new_mask; + sigfillset(&new_mask); + pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_); + } + + // Destructor restores the previous signal mask + ~Blocker() { + pthread_sigmask(SIG_SETMASK, &old_mask_, 0); + } + +private: + // The previous signal mask + sigset_t old_mask_; +}; + +} + // The implementation of the Thread class. // // This internal state is not deleted until the thread terminates and is either @@ -105,6 +131,7 @@ Thread::Thread(const boost::function& main) : impl_(NULL) { auto_ptr impl(new Impl(main)); + Blocker blocker; const int result = pthread_create(&impl->tid_, NULL, &Impl::run, impl.get()); // Any error here?