bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
std::thread t1(&HelloWorld::myThread,this);//创建一个分支线程,回调到myThread函数里
t1.join();
// t1.detach();
CCLOG("in major thread");//在主线程
return true;
}
void HelloWorld::myThread()
{
CCLOG("in my thread");
}运行结果如下图:std::thread t1(&HelloWorld::myThread,this);//创建一个分支线程,回调到myThread函数里 t1.detach();运行结果如下:
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
std::thread t1(&HelloWorld::myThread,this,10,20);//创建一个分支线程,回调到myThread函数里
t1.join();
// t1.detach();
CCLOG("in major thread");//在主线程
return true;
}
void HelloWorld::myThread(int first,int second)
{
CCLOG("in my thread,first = %d,second = %d",first,second);
}输出结果如下图:恩,这篇先讲到这里吧。下篇讲下互斥量,最后以一个抄袭的例子潇洒的结束掉线程的一生
尊重原创,转载请注明来源:
Cocos2dx 3.0 过渡篇(二十六)C++11多线程std::thread的简单使用(上),布布扣,bubuko.com
Cocos2dx 3.0 过渡篇(二十六)C++11多线程std::thread的简单使用(上)
原文:http://blog.csdn.net/star530/article/details/24186783