summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-20 18:00:53 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-20 18:00:53 (GMT)
commit1121db92c31ba0413038c32e69e12b193ed75d0f (patch)
tree815d40d12c8ad1b3d84a498500f94f5e1b7a22ed
parent5b7544ba9c39209a3108d86f3c0d861bb0fe3eb3 (diff)
Fix race condition in LoadJob
Currently `extracttest` has random failures when we check properties with the libarchive plugin. This happens because there is a race condition between `LoadJob::onFinished()` (where we read some `LoadJob` members) and `LoadJob::onNewEntry()` (where we write those members). `onFinished()` is called when `list()` returns, in `LoadJob::doWork()`. But that might happen before `onNewEntry()` is called, since they are executed in two different threads. This patch puts the `onFinished()` call in the event queue, just like the single-thread case does (where we emit the `finished` signal from `CliInterface`). Differential Revision: D3111
-rw-r--r--kerfuffle/jobs.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp
index efee50f..5a4429e 100644
--- a/kerfuffle/jobs.cpp
+++ b/kerfuffle/jobs.cpp
@@ -260,7 +260,11 @@ void LoadJob::doWork()
bool ret = archiveInterface()->list();
if (!archiveInterface()->waitForFinishedSignal()) {
- onFinished(ret);
+ // onFinished() needs to be called after onNewEntry(), because the former reads members set in the latter.
+ // So we need to put it in the event queue, just like the single-thread case does by emitting finished().
+ QTimer::singleShot(0, this, [=]() {
+ onFinished(ret);
+ });
}
}