mirror of https://github.com/axmolengine/axmol.git
closed issue#4123:fixed thread deadlock if new functions are added in callback.
This commit is contained in:
parent
b54607bfc9
commit
387bd544bf
|
@ -948,11 +948,14 @@ void Scheduler::update(float dt)
|
||||||
// And almost never there will be functions scheduled to be called.
|
// And almost never there will be functions scheduled to be called.
|
||||||
if( !_functionsToPerform.empty() ) {
|
if( !_functionsToPerform.empty() ) {
|
||||||
_performMutex.lock();
|
_performMutex.lock();
|
||||||
for( const auto &function : _functionsToPerform ) {
|
// fixed #4123: Save the callback functions, they must be invoked after '_performMutex.unlock()', otherwise if new functions are added in callback, it will cause thread deadlock.
|
||||||
function();
|
auto temp = _functionsToPerform;
|
||||||
}
|
|
||||||
_functionsToPerform.clear();
|
_functionsToPerform.clear();
|
||||||
_performMutex.unlock();
|
_performMutex.unlock();
|
||||||
|
for( const auto &function : temp ) {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue