closed issue#4123:fixed thread deadlock if new functions are added in callback.

This commit is contained in:
Dhilan007 2014-02-24 21:08:05 +08:00
parent b54607bfc9
commit 387bd544bf
1 changed files with 6 additions and 3 deletions

View File

@ -948,11 +948,14 @@ void Scheduler::update(float dt)
// And almost never there will be functions scheduled to be called.
if( !_functionsToPerform.empty() ) {
_performMutex.lock();
for( const auto &function : _functionsToPerform ) {
function();
}
// 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.
auto temp = _functionsToPerform;
_functionsToPerform.clear();
_performMutex.unlock();
for( const auto &function : temp ) {
function();
}
}
}