cocos2d x多執行緒操作

2021-09-23 08:02:09 字數 412 閱讀 9881

先頭檔案定義:

void threada();

再在.cpp檔案中新增

//1.引入標頭檔案#include std::thread t1(&login::threada,this);//取login的位址

t1.detach();//主線程和子執行緒互不影響

阻塞主線程:執行子執行緒完了後才執行主線程

cclog("first thread id is: %x",this_thread::get_id());

void login::threada()

這樣就算是起了乙個新的執行緒,和主線程同時存在,這個執行緒睡眠5秒鐘後輸出了乙個日誌。

如果程式中途被關閉新的執行緒還在繼續執行,那麼程式關閉的時候會出錯。

cocos2dx 多執行緒

2.加標頭檔案 include pthread pthread.h 直接上 編譯出錯 fatal error c1083 無法開啟包括檔案 sched.h no such file or directory,在pthread的相同目錄下有這個標頭檔案,在專案的屬性中加入這個標頭檔案的路徑就可以了 3...

cocos2dx學習筆記(多執行緒)

多執行緒的實現 pthreadtest.h ifndef mtnotificationqueue h define mtnotificationqueue h include cocos2d.h include include pthread pthread.h using ns cc using ...

cocos2dx建立執行緒

為了防止程式假死,需要另起執行緒處理網路連線。好吧,那就從建立執行緒開始。這次我的環境是在mac下。在網上查閱和參考了很多資料,感謝這些無私奉獻的前輩們的努力。進入話題。標頭檔案 cpp view plain copy pthread t th socket 起這個名字本打算用在socket上的 i...