From 1879f67f1532fe1644a0657a5d52f063b43c0bf4 Mon Sep 17 00:00:00 2001 From: Michael Greene Date: Thu, 16 Aug 2012 16:42:02 -0400 Subject: [PATCH] Fix: threads should be created in DETACHED state Signed-off-by: Michael Greene Signed-off-by: Mathieu Desnoyers --- liblttng-ust/lttng-ust-comm.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index cca5dcf8..842876fb 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -928,6 +928,7 @@ void __attribute__((constructor)) lttng_ust_init(void) { struct timespec constructor_timeout; sigset_t sig_all_blocked, orig_parent_mask; + pthread_attr_t thread_attr; int timeout_mode; int ret; @@ -977,13 +978,22 @@ void __attribute__((constructor)) lttng_ust_init(void) ERR("pthread_sigmask: %s", strerror(ret)); } - ret = pthread_create(&global_apps.ust_listener, NULL, + ret = pthread_attr_init(&thread_attr); + if (ret) { + ERR("pthread_attr_init: %s", strerror(ret)); + } + ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); + if (ret) { + ERR("pthread_attr_setdetachstate: %s", strerror(ret)); + } + + ret = pthread_create(&global_apps.ust_listener, &thread_attr, ust_listener_thread, &global_apps); if (ret) { ERR("pthread_create global: %s", strerror(ret)); } if (local_apps.allowed) { - ret = pthread_create(&local_apps.ust_listener, NULL, + ret = pthread_create(&local_apps.ust_listener, &thread_attr, ust_listener_thread, &local_apps); if (ret) { ERR("pthread_create local: %s", strerror(ret)); @@ -991,6 +1001,10 @@ void __attribute__((constructor)) lttng_ust_init(void) } else { handle_register_done(&local_apps); } + ret = pthread_attr_destroy(&thread_attr); + if (ret) { + ERR("pthread_attr_destroy: %s", strerror(ret)); + } /* Restore original signal mask in parent */ ret = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL); -- 2.34.1