Projects > cpp > Issues > Bug #4123

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Thread deadlock if new functions are added in callback of Scheduler:: performFunctionInCocosThread

Bug #4123 [Closed]
WenHai 2014-02-24 11:51 . Updated about 11 years ago
dumganhar 2014-02-24 13:47
  • Subject changed from thread can cause deadlock in Scheduler::update. to Thread deadlock if new functions are added in callback of Scheduler:: performFunctionInCocosThread
dumganhar 2014-02-25 02:18
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:a103fc611caf219589455837a5248174b75f3ebb.

zhangxm 2014-02-26 12:30

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();
}
zhangxm 2014-02-26 12:34

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();
}

Atom PDF

Status:Closed
Start date:2014-02-24
Priority:Normal
Due date:
Assignee:WenHai
% Done:

100%

Category:all
Target version:3.0-rc0