From 387bd544bfb9e5b583512c8a17f8ab22f7bc5f5b Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 24 Feb 2014 21:08:05 +0800 Subject: [PATCH] closed issue#4123:fixed thread deadlock if new functions are added in callback. --- cocos/2d/CCScheduler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cocos/2d/CCScheduler.cpp b/cocos/2d/CCScheduler.cpp index 8ea4223de2..110f34aad9 100644 --- a/cocos/2d/CCScheduler.cpp +++ b/cocos/2d/CCScheduler.cpp @@ -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(); + } + } }