pthread 造成 CCScene::node(); 停止

各位大大。。
小弟剛開始使用Cocos2D-X一個多月,現在遇到一個狀況,我寫的是個socket連線程或;以pthread_create()建立一個Thread,接著建立Socket連線,connect(),然後以SIGIO來處理Socket的讀寫事件,將讀取下來的封包儲存後在Thread中來處理;
在iOS的模擬器環境下一直很正常,昨日接上iPad實機測試,結果在c的地方就會卡住不動;反覆試了多次,有時(很少)會PASS沒事,若將Thread取消也沒事,或是將SIGIO拿掉(Thread保留)也會正常。。
單步追進去,看是卡在CCScene *pRet = new CCScene();這行;還望高手指點,謝謝!

Sorry,I just saw the FAQ, so I post again…

I have a problem about using thread in Cocos2d-X, I create a thread by pthread_create() first,then create socket(),connect()…use SIGIO to get the socket’s r/w signal, store the data received from socket, and process the data in the thread;
It’s work find on the iOS simulator (iPad 5.1 simulator). but when I test on the iPad device, It will stopped on the code ‘CCScene scene = CCScene::node;’.I tried few times, remark the thread part the scene will work fine, or remark the SIGIO (sigfillset & sigaction) will work fine too….
I trace the code, found it’s stopped on ’CCScene
pRet = new CCScene();’, Please someone help me

Don’t invoke engine’s codes in a new thread.
It is not thread-safe.

Minggo Zhang wrote:

Don’t invoke engine’s codes in a new thread.
It is not thread-safe.

Dear Minggo…

Thank you for your reply…

I check my source code, and found I only use CCLog(); for debug, so I removed all the CCLog(); in the thread, but it’s still stopped while CCLayer::init(), so I try to remark the source code in my thread to find out which code make the Cocos2d-X holding…
and I found if I call socket’s send(); order than Cocos2d-X will stopped while CCLayer::init()……

what’s your suggestion for my situation? And what is the best way to create a socket Client application with Cocos2d-X engine you recommend ? Is there any sample code that I can study for this issue ?

Thanks again

Best Regards,

Atwood Yen

I think you can refer to CCTextureCache::addImageAsync().