fixed #11339 : [v3.6] Crash after hot update by invoking cc.game.restart(). (#11348)

* fixed #11339 : [v3.6] Crash after hot update.
MessageQueue::terminateConsumerThread needs to wait consumer thead to exit. So don't detach consumer thead and we need to join the thread at the end of terminateConsumerThread.

* Delete _consumerThead after join.
This commit is contained in:
James Chen
2022-06-06 13:35:09 +08:00
committed by GitHub
parent 423ce5fa6b
commit 5ae5dbbd54
2 changed files with 9 additions and 2 deletions
+8 -2
View File
@@ -124,8 +124,7 @@ void MessageQueue::runConsumerThread() noexcept {
_reader.terminateConsumerThread = false;
_reader.flushingFinished = false;
std::thread consumerThread(&MessageQueue::consumerThreadLoop, this);
consumerThread.detach();
_consumerThread = ccnew std::thread(&MessageQueue::consumerThreadLoop, this);
_workerAttached = true;
}
@@ -141,6 +140,13 @@ void MessageQueue::terminateConsumerThread() noexcept {
kick();
event.wait();
if (_consumerThread != nullptr) {
if (_consumerThread->joinable()) {
_consumerThread->join();
}
}
CC_SAFE_DELETE(_consumerThread);
}
void MessageQueue::finishWriting() noexcept {