From caeb203f5188aafccc667c1afc42a49df80d0747 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 6 Oct 2009 16:22:32 +0200 Subject: bugfix: potential race condition when queue worker threads were terminated --- runtime/wti.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/wti.c b/runtime/wti.c index 9d0560dd..e624899b 100644 --- a/runtime/wti.c +++ b/runtime/wti.c @@ -114,7 +114,12 @@ wtiSetState(wti_t *pThis, bool bNewVal) /* Cancel the thread. If the thread is not running. But it is save and legal to - * call wtiCancelThrd() in such situations. + * call wtiCancelThrd() in such situations. This function only returns when the + * thread has terminated. Else we may get race conditions all over the code... + * Note that when waiting for the thread to terminate, we do a busy wait, checking + * progress every 10ms. It is very unlikely that we will ever cancel a thread + * and, if so, it will only happen at the end of the rsyslog run. So doing this + * kind of not optimal wait is considered preferable over using condition variables. * rgerhards, 2008-02-26 */ rsRetVal @@ -127,6 +132,10 @@ wtiCancelThrd(wti_t *pThis) if(wtiGetState(pThis)) { dbgoprint((obj_t*) pThis, "canceling worker thread\n"); pthread_cancel(pThis->thrdID); + /* now wait until the thread terminates... */ + while(wtiGetState(pThis)) { + srSleep(0, 10000); + } } RETiRet; -- cgit