Notify the request thread of shutdown only if it's waiting

This avoids a deadlock that would occur if notify_all() is called before the thread is waiting
This commit is contained in:
smallmodel 2025-03-13 22:37:21 +01:00
parent 456b660b2a
commit 06a12246f5
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 12 additions and 11 deletions

View file

@ -210,7 +210,13 @@ void UpdateCheckerThread::Shutdown()
if (osThread) {
// Notify and shutdown the thread
{
// Wait until the request thread is ready
std::lock_guard<std::mutex> l(clientWakeMutex);
clientWake.notify_all();
}
// Wait for the thread to exit
osThread->join();
delete osThread;
@ -358,19 +364,15 @@ void UpdateCheckerThread::RequestThread()
InitClient();
while (handle && shouldBeActive) {
std::unique_lock<std::mutex> l(clientWakeMutex);
DoRequest();
RequestThreadSleep();
const std::chrono::seconds interval = std::chrono::seconds(Q_max(1, com_updatecheck_interval->integer) * 60);
clientWake.wait_for(l, interval);
}
ShutdownClient();
requestThreadIsActive = qfalse;
}
void UpdateCheckerThread::RequestThreadSleep()
{
const std::chrono::seconds interval = std::chrono::seconds(Q_max(1, com_updatecheck_interval->integer) * 60);
std::unique_lock<std::mutex> l(clientWakeMutex);
clientWake.wait_for(l, interval);
}

View file

@ -61,7 +61,6 @@ private:
bool ParseVersionNumber(const char *value, int& major, int& minor, int& patch) const;
void RequestThread();
void RequestThreadSleep();
void DoRequest();
private: