From b9e2113b5793706b2d28f4096faad919a625dd9f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Aug 2016 08:56:44 -0700 Subject: [PATCH 1/2] libmultipath/waiter.c: Call pthread_join() upon thread exit pthread_kill() delivers a signal asynchronously. Hence add a pthread_join() call in stop_waiter_thread() to wait until the waiter thread has stopped. The following section from the pthread_join() manpage is relevant in this context: Failure to join with a thread that is joinable (i.e., one that is not detached), produces a "zombie thread". Avoid doing this, since each zombie thread consumes some system resources, and when enough zombie threads have accumulated, it will no longer be possible to create new threads (or processes). Signed-off-by: Bart Van Assche --- libmultipath/waiter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libmultipath/waiter.c b/libmultipath/waiter.c index 995ea1a..6692753 100644 --- a/libmultipath/waiter.c +++ b/libmultipath/waiter.c @@ -61,6 +61,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs) mpp->waiter = (pthread_t)0; pthread_cancel(thread); pthread_kill(thread, SIGUSR2); + pthread_join(thread, NULL); } /* -- 2.9.2