cocos2d-x3.2 下使用多线程
事实上在cocos2dx下使用多线程事实上就是用C++去写,这里提供几个简单的样例:
原文地址:http://blog.csdn.net/qqmcy/article/details/36227377
1、
//
// PublicScene.cpp
// testthirdone
//
// Created by 杜甲 on 14-7-1.
// void hello()
{
log("hello thread");
} bool PublicScene::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!Scene::init()); std::thread t1(hello);
t1.join();
log("主线程"); bRet = true;
} while (0);
return bRet;
} std::thread t1(hello);
t1.join();
log("主线程");
2、
//
// PublicScene.cpp
// testthirdone
//
// Created by 杜甲 on 14-7-1.
//
// void hello()
{
log("hello thread");
} bool PublicScene::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!Scene::init()); std::vector<std::thread> threads;
for (int i = 0; i < 5; ++i)
{
threads.push_back(std::thread([ = ]()
{
log("%s",StringUtils::format(" thread %d",i).c_str());
}));
} for (auto& thread :threads) {
thread.join();
} log("Main Thread"); bRet = true;
} while (0);
return bRet;
}
3、
//
// PublicScene.cpp
// testthirdone
//
// Created by 杜甲 on 14-7-1.
//
// void hello()
{
log("hello thread");
} bool PublicScene::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!Scene::init()); std::mutex m;
std::thread t1([&m](){
m.lock();
for (int i = 0; i < 10; i++) { log("%s",StringUtils::format(" thread1 %d",i).c_str()); }
m.unlock();
}); std::thread t2([&m](){ m.lock();
for (int i = 0; i < 10; i++) { log("%s",StringUtils::format(" thread2 %d",i).c_str()); }
m.unlock();
}); t1.join();
t2.join(); log("Main Thread"); bRet = true;
} while (0);
return bRet;
}
cocos2d-x3.2 下使用多线程的更多相关文章
- C#实现http协议下的多线程文件传输
用C#实现HTTP协议下的多线程文件传输转自 http://developer.51cto.com/art/201105/263066_all.htm C#(C Sharp)是微软(Microsof ...
- 【转】 Linux下的多线程编程
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/原文链接:http://www.cnblogs.com/gnuhpc/archive/2012/12/07/280 ...
- Linux下的多线程编程
1 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的 Unix也支持线程的概念,但是在一个进程(proces ...
- 多线程编程之Linux环境下的多线程(三)
前面两篇文章都讲述了Linux环境下的多线程编程基础知识,也附带了典型实例.本文主要比较一下Linux环境与Windows环境下的多线程编程区别. 看待技术问题要瞄准其本质,不管是WIN32.Linu ...
- 多线程编程之Linux环境下的多线程(一)
一.Linux环境下的线程 相对于其他操作系统,Linux系统内核只提供了轻量级进程的支持,并未实现线程模型.Linux是一种“多进程单线程”的操作系统,Linux本身只有进程的概念,而其所谓的“线程 ...
- 【转】Linux下的多线程编程
1 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的 Unix也支持线程的概念,但是在一个进程(proces ...
- (转)浅谈.NET下的多线程和并行计算(一)前言
转载——原文地址:http://www.cnblogs.com/lovecindywang/archive/2009/12/25/1632014.html 作为一个ASP.NET开发人员,在之前的开发 ...
- C#Stimulator项目>>>C/C++ DLL的生成和调用,Windows下的多线程
Windows下的多线程 http://blog.csdn.net/ganpengjin1/article/category/2541791 使用C/C++建立DLL,环境VS2013 新建Win32 ...
- 《转》Linux下的多线程编程
原地址:http://linux.chinaunix.net/doc/program/2001-08-11/642.shtml 1 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程 ...
- Windows平台下的多线程编程
线程是进程的一条执行路径,它包含独立的堆栈和CPU寄存器状态,每个线程共享所有的进程资源,包括打开的文件.信号标识及动态分配的内存等.一个进程内的所有线程使用同一个地址空间,而这些线程的执行由系统调度 ...
随机推荐
- Unity3D中C#和JS的方法互相調用
因为Unity3D中一些腳本的方法仅仅能用在JS中.在C#中是無效的,而C#能够與服務器端通訊,JS本身卻不行.所以勢必會遇到這兩種語言腳本中方法的互相調用,下面是演示样例. 兩個文件 test1.j ...
- webRequest
chrome.webRequest 描述: 使用 chrome.webRequest API 监控与分析流量,还可以实时地拦截.阻止或修改请求. 可用版本: 从 Chrome 17 开始支持. 权 ...
- 2015.05.15,外语,学习笔记-《Word Power Made Easy》 02 “如何谈论医生”
包括Sessions 4-6: Prefix Person,nous,etc. Practice,etc. Adjective internus内部 internist [ɪn'tɝnɪst] n.内 ...
- HTML iframe 和 frameset 的区别
转自:http://www.cnblogs.com/polk6/archive/2013/05/24/3097430.html HTML iframe 和 frameset 的区别 iframe 和 ...
- 12. Integer to Roman[M]整数转罗马数字
题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...
- POJ 2353 DP
双向DP+记录路径. // by SiriusRen #include <stack> #include <cstdio> #include <cstring> u ...
- c# CacheHelper缓存帮助类
一.开篇 主要功能:改善程序性能.服务器的响应速度,尤其是当数据的处理过程变得复杂以及访问量变大时,变得比较明显.有些数据并非时刻在发生变化,如果我们可以将一些变化不频繁的数据的最终计算结果(包括页面 ...
- c# byte转化为string
byte[] bt = new byte[] { 10, 11, 33, 44, 2 }; string str=string.Join(",",bt.Select(t=>t ...
- BZOJ4819: [Sdoi2017]新生舞会(01分数规划)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1029 Solved: 528[Submit][Status][Discuss] Descripti ...
- 用过的jQuery记录
var list= $('input:radio[name="name"]:checked').val(); //选择input中单选name为“name”的并且是选中状态的 in ...