From 27808888a642505bd26b2f56f2ee464cdb7a2c8b Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Mon, 8 Aug 2022 03:13:08 +0700 Subject: [PATCH] db: start the processing thread after all fields are initialized Initializing `zmDbQueue::mThread` with initializer list makes the thread start in the middle of object initialization. This means `zmDbQueue:: process()` could start and reach mCondition.wait(lock); before `std:: wait_condition`'s constructor, which causes deadlock. To make sure thread won't start before object initialize, move `mThread`'s initialization to constructor's body. This _at last_ solves the random zmu deadlock issue that has plagued my setup for almost a year. --- src/zm_db.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/zm_db.cpp b/src/zm_db.cpp index eda0b3166..29e805a65 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -227,9 +227,10 @@ zmDbRow::~zmDbRow() { } zmDbQueue::zmDbQueue() : - mThread(&zmDbQueue::process, this), mTerminate(false) -{ } +{ + mThread = std::thread(&zmDbQueue::process, this); +} zmDbQueue::~zmDbQueue() { stop();