From 12aabf79603a58d13678f0576d15ad2a57fa46e3 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Fri, 24 May 2019 14:49:49 +0300 Subject: [PATCH] Reader: fix thread safety bugs in PageLoader --- YACReader/goto_flow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/YACReader/goto_flow.cpp b/YACReader/goto_flow.cpp index 167074de..57cb718a 100644 --- a/YACReader/goto_flow.cpp +++ b/YACReader/goto_flow.cpp @@ -260,6 +260,8 @@ PageLoader::PageLoader(QMutex * m): PageLoader::~PageLoader() { + //TODO this destructor never runs. If it is ever called, it will hang, because + //the implementation is broken due to the absolutely endless loop in run(). mutex->lock(); condition.wakeOne(); mutex->unlock(); @@ -284,9 +286,11 @@ void PageLoader::generate(int index, QSize size,const QByteArray & rImage) start(); else { + mutex->lock(); // already running, wake up whenever ready restart = true; condition.wakeOne(); + mutex->unlock(); } } @@ -314,7 +318,7 @@ void PageLoader::run() // put to sleep mutex->lock(); - if (!this->restart) + while (!this->restart) condition.wait(mutex); restart = false; mutex->unlock();