OSDN Git Service

ensure SIGPIPE is ignored only for the current thread
authorIvailo Monev <xakepa10@gmail.com>
Thu, 16 Sep 2021 14:50:14 +0000 (17:50 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 16 Sep 2021 14:51:16 +0000 (17:51 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/kernel/qcore_unix_p.h

index a692727..af49456 100644 (file)
@@ -104,17 +104,14 @@ inline timeval operator*(const timeval &t1, int mul)
 
 static inline void qt_ignore_sigpipe()
 {
-    // Set to ignore SIGPIPE once only.
-    static QAtomicInt atom(0);
-    if (!atom) {
-        // More than one thread could turn off SIGPIPE at the same time
-        // But that's acceptable because they all would be doing the same
-        // action
+    // ignore SIGPIPE once per-thread only
+    thread_local bool sigpipe_ignored = false;
+    if (!sigpipe_ignored) {
         struct sigaction noaction;
         memset(&noaction, 0, sizeof(noaction));
         noaction.sa_handler = SIG_IGN;
         ::sigaction(SIGPIPE, &noaction, nullptr);
-        atom = 1;
+        sigpipe_ignored = true;
     }
 }