[graphics/okular/release/26.08] core: fix(core): use atomic for FontExtractionThread::mGoOn to prevent data race
Albert Astals Cid <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit fbaec8fa4aea3becf033ddc6c2fe40f202ccef1c by Albert Astals Cid, on behalf of zhang shoucheng.
Committed on 19/07/2026 at 00:12.
Pushed by aacid into branch 'release/26.08'.
fix(core): use atomic for FontExtractionThread::mGoOn to prevent data race
mGoOn is written by the main thread in stopExtraction() and read
by the worker thread in run(). A plain bool across threads without
synchronization is a data race and undefined behavior per the C++
memory model.
Change mGoOn from bool to std::atomic<bool>. This establishes a
proper happens-before relationship between the stop signal and the
worker loop, and prevents the compiler from caching the value in a
register or hoisting the read out of the loop.
(cherry picked from commit 63342a4c2d90b66ff8e4b6a7a0eda4a9f84f298b)
M +3 -1 core/generator_p.h
https://invent.kde.org/graphics/okular/-/commit/fbaec8fa4aea3becf033ddc6c2fe40f202ccef1c
diff --git a/core/generator_p.h b/core/generator_p.h
index 4b6ddf599..ba7a64c63 100644
--- a/core/generator_p.h
+++ b/core/generator_p.h
@@ -17,6 +17,8 @@
#include <QSet>
#include <QThread>
+#include <atomic>
+
class QEventLoop;
#include "generator.h"
@@ -180,7 +182,7 @@ protected:
private:
Generator *mGenerator;
int mNumOfPages;
- bool mGoOn;
+ std::atomic<bool> mGoOn;
};
}