From 7ef36b5c15bed963491b04263d48b6a6e65c4666 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 15 Apr 2016 10:49:07 +0000 Subject: [PATCH] Work around a linux libc bug causing a crash in TaskPool Summary: Doing a pthread_detach while the thread is exiting can cause crashes or other mischief, so we make sure the thread stays around long enough. The performance impact of the added synchronization should be minimal, as the parent thread is already holding a mutex, so I am just making sure it holds it for a little while longer. It's possible the new thread will block on this mutex immediately after startup, but it should be unblocked really quickly and some blocking is unavoidable if we actually want to have this synchronization. Reviewers: tberghammer Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D19153 llvm-svn: 266423 --- lldb/source/Utility/TaskPool.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lldb/source/Utility/TaskPool.cpp b/lldb/source/Utility/TaskPool.cpp index 75fe59d1e711..c5c63a20cebc 100644 --- a/lldb/source/Utility/TaskPool.cpp +++ b/lldb/source/Utility/TaskPool.cpp @@ -61,8 +61,9 @@ TaskPoolImpl::AddTask(std::function&& task_fn) if (m_thread_count < max_threads) { m_thread_count++; - lock.unlock(); - + // Note that this detach call needs to happen with the m_tasks_mutex held. This prevents the thread + // from exiting prematurely and triggering a linux libc bug + // (https://sourceware.org/bugzilla/show_bug.cgi?id=19951). std::thread (Worker, this).detach(); } }