We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
Thread deadlock if new functions are added in callback of Scheduler:: performFunctionInCocosThread
Thread deadlock if new functions are added in callback of Scheduler:: performFunctionInCocosThread
Bug #4123 [Closed]
I think it is better to modify the function Scheduler::performFunctionInCocosThread(), when invoking this function in the same thread, it should not lock the mutex.
1
2
3
4
5
6
7
8
9
10
void Scheduler::performFunctionInCocosThread(const std::function<void ()> &function)
{
if ( run on a thread other than cocos thread)
_performMutex.lock();
_functionsToPerform.push_back(function);
if ( run on a thread other than cocos thread)
_performMutex.unlock();
}
But it also will have problem, because it modified _performMutex
when looping. So may be better way is
1
2
3
4
5
6
7
8
9
10
11
12
13
void Scheduler::performFunctionInCocosThread(const std::function<void ()> &function)
{
if (run on the same thread as cocos thread)
print warning
return
_performMutex.lock();
_functionsToPerform.push_back(function);
_performMutex.unlock();
}
This bug was reported from http://www.cocoachina.com/bbs/read.php?tid=186214&toread=1