How to use pthread

来源:互联网 发布:深圳数据分析师培训 编辑:程序博客网 时间:2024/06/05 23:43

How to use pthread

Now, you can use pthread in cocos2d-x, but there are some limitations.

1. Don't call functions that invoke retain(), release() or autorelease(), because they are not thread-safe.
cocos2d-x use these functions every where, so don't invoke any engine code in a new thread.

2. If you want to load resources in a new thread, you can use CCTextureCache::addImageAsync().

3. pthread_cond_wait() seems have a bug, it can not wait at first time.

If we make retain(), release() and autorealese() thread-safe, then we should use mutex. Because engine
releases the autorelease pool after drawing a frame, then it may cause performance issue. By the way,
opengle context is not thread-safe.