summaryrefslogtreecommitdiffstats
path: root/runtime/wti.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-10-06 16:22:32 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-10-06 16:22:32 +0200
commitcaeb203f5188aafccc667c1afc42a49df80d0747 (patch)
tree06fcd5a8e95992845a90da35e711d542b525d8d2 /runtime/wti.c
parent54c375eb5b28d70fca023f7ca2fcc2cd0a4fa7ba (diff)
downloadrsyslog-caeb203f5188aafccc667c1afc42a49df80d0747.tar.gz
rsyslog-caeb203f5188aafccc667c1afc42a49df80d0747.tar.xz
rsyslog-caeb203f5188aafccc667c1afc42a49df80d0747.zip
bugfix: potential race condition when queue worker threads were terminated
Diffstat (limited to 'runtime/wti.c')
-rw-r--r--runtime/wti.c11
1 files changed, 10 insertions, 1 deletions
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;