From ac3c136332aee901536f47a3e79442a27bb58bb4 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 8 Apr 2020 10:23:59 +0300 Subject: [PATCH] Fix race condition at the start up of system call dispatcher There is a possibility that the dispatcher thread is started before its state is initialized which causes it to appear as inactive when it tries to enter the send loop and actually exists early. This is a clear design flaw in the runner class but for the time being this disgusting fix will have to suffice. --- src/dispatch.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dispatch.cc b/src/dispatch.cc index be2be0d..1d5c36a 100644 --- a/src/dispatch.cc +++ b/src/dispatch.cc @@ -86,6 +86,9 @@ void kvz_rtp::dispatcher::dispatch_runner(kvz_rtp::dispatcher *dispatcher, kvz_r std::unique_lock lk(m); kvz_rtp::transaction_t *t = nullptr; + while (!dispatcher->active()) + ; + while (dispatcher->active()) { if ((t = dispatcher->get_transaction()) == nullptr) { dispatcher->get_cvar().wait(lk);