Skip to content

A cross platform c++11 API for the cocos2d-x environment. It allows you to call back on main thread when using c++11 standard concurrency library. It can take lambdas or function pointers.

Notifications You must be signed in to change notification settings

radif/emjCCMainThreadCaller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

emjCCMainThreadCaller

A cross platform c++11 API for the cocos2d-x game engine. It allows you to call back on main thread when using c++11 standard concurrency library.

you can use it with std::async, std::thread or any other native thread implementation.

Useful for working with threads callbacks

 //you need to save the future outside the stack context to let the tread run trully in background; if you don't do this, the operation will be synchronous;
 struct FutureHolder {std::future<void> future = nullptr;};

 FutureHolder * f=new FutureHolder;
 f->future=std::async(std::launch::async, [=]()
 std::cout << "Hello from working thread with Thread ID:"<<std::this_thread::get_id()<<std::endl;

 emjCCPlatformSupport::call_on_main_thread([=](){
     std::cout << "Hello from the Main Thread with ID:"<<std::this_thread::get_id()<<std::endl;
     delete f; //deleting the future and holder. If you fail to delete you will have a leak
 });

 });

About

A cross platform c++11 API for the cocos2d-x environment. It allows you to call back on main thread when using c++11 standard concurrency library. It can take lambdas or function pointers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages