how to use mutil-thread?

how to use mutil-thread in cocos2d-x?I want to run a new thread on background。

I just write some code that enable the cocos2d-x to run thread using the pthread . you can try it.

en,thanks very much.where can i get these code?

you can learn how to by this page https://computing.llnl.gov/tutorials/pthreads/

pthread interfaces are available on both ios & android.
But please don’t invoke cocos2d graphic interfaces in new created thread, otherwise it will cause the crash in opengles state machine. And take care that CCAutoreleasePool isn’t thread-safe. CCObjects with autorelease flag will be released at the end of each msg loop in UI main thread, you mustn’t use them in other threads.

Walzer Wang wrote:

pthread interfaces are available on both ios & android.
But please don’t invoke cocos2d graphic interfaces in new created thread, otherwise it will cause the crash in opengles state machine. And take care that CCAutoreleasePool isn’t thread-safe. CCObjects with autorelease flag will be released at the end of each msg loop in UI main thread, you mustn’t use them in other threads.

I met a similar problem as you talk,
and didn’t know how to resolve it
can you give me some suggestion ?

Hi Zhao, you can process network, file io and any other cases without drawing in your new thread, then set flags / notify events to cocos2d main thread.
When the main thread see the flag in its drawing loop and deal with it.
Generally speaking, the network / file io results cannot affect the graphic immediately, but set a flag, and wait until next loop in cocos2d main thread.

thank you for your post……i can find some good reference.

Is it possible to do background opengl operations in the new thread ? For example, the GPUImage library[1] applies filters on the images using shaders in the background without rendering anything on screen. Is it possible to run cocos2d-x in main thread and GPUImage library in a background thread?

[1][https://github.com/Dexterp37/GPUImage/]