From 05a9730e53f00e66659d081396bfbc32af873248 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 26 Aug 2013 12:24:27 +0000 Subject: [PATCH] - More fixes for bug#519: for the threaded case test if the bg thread has been killed, on ub_ctx_delete, to avoid hangs. git-svn-id: file:///svn/unbound/trunk@2946 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 4 ++++ libunbound/libunbound.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 4d75e0377..286095dac 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +26 Aug 2013: Wouter + - More fixes for bug#519: for the threaded case test if the bg + thread has been killed, on ub_ctx_delete, to avoid hangs. + 22 Aug 2013: Wouter - more fixes that I overlooked. - review fixes from Willem. diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index ae865a71e..999478ef3 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -60,6 +60,9 @@ #include "services/localzone.h" #include "services/cache/infra.h" #include "services/cache/rrset.h" +#ifdef HAVE_PTHREAD +#include +#endif #if defined(UB_ON_WINDOWS) && defined (HAVE_WINDOWS_H) #include @@ -155,11 +158,9 @@ delq(rbnode_t* n, void* ATTR_UNUSED(arg)) context_query_delete(q); } -void -ub_ctx_delete(struct ub_ctx* ctx) +/** stop the bg thread */ +static void ub_stop_bg(struct ub_ctx* ctx) { - struct alloc_cache* a, *na; - if(!ctx) return; /* stop the bg thread */ lock_basic_lock(&ctx->cfglock); if(ctx->created_bg) { @@ -195,7 +196,28 @@ ub_ctx_delete(struct ub_ctx* ctx) else { lock_basic_unlock(&ctx->cfglock); } +} + +void +ub_ctx_delete(struct ub_ctx* ctx) +{ + struct alloc_cache* a, *na; + int do_stop = 1; + if(!ctx) return; + /* see if bg thread is created and if threads have been killed */ + /* no locks, because those may be held by terminated threads */ + /* for processes the read pipe is closed and we see that on read */ +#ifdef HAVE_PTHREAD + if(ctx->created_bg && ctx->dothread) { + if(pthread_kill(ctx->bg_tid, 0) == ESRCH) { + /* thread has been killed */ + do_stop = 0; + } + } +#endif /* HAVE_PTHREAD */ + if(do_stop) + ub_stop_bg(ctx); modstack_desetup(&ctx->mods, ctx->env); a = ctx->alloc_list; -- 2.47.2