[PATCH] Thread pools: create threads in detached state

Piotr Sikora piotrsikora at google.com
Thu Aug 18 00:29:27 UTC 2016


# HG changeset patch
# User Piotr Sikora <piotrsikora at google.com>
# Date 1471265524 25200
#      Mon Aug 15 05:52:04 2016 -0700
# Node ID f5fa7a77bcf49091d4315b18f2bca098ca314b06
# Parent  c131f20c9562387f94a268440594c288725d3ba8
Thread pools: create threads in detached state.

This prevents resource leak, since those threads are never joined.

Found with ThreadSanitizer.

Signed-off-by: Piotr Sikora <piotrsikora at google.com>

diff -r c131f20c9562 -r f5fa7a77bcf4 src/core/ngx_thread_pool.c
--- a/src/core/ngx_thread_pool.c
+++ b/src/core/ngx_thread_pool.c
@@ -137,6 +137,13 @@ ngx_thread_pool_init(ngx_thread_pool_t *
         return NGX_ERROR;
     }
 
+    err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    if (err) {
+        ngx_log_error(NGX_LOG_ALERT, log, err,
+                      "pthread_attr_setdetachstate() failed");
+        return NGX_ERROR;
+    }
+
 #if 0
     err = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
     if (err) {



More information about the nginx-devel mailing list