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寄存器状态,每个线程共享所有的进程资源,包括打开的文件.信号标识及动态分配的内存等.一个进程内的所有线程使用同一个地址空间,而这些线程的执行由系统调度 ...
随机推荐
- [Angular] Component's dependency injection
An Angular service registered on the NgModule is globally visible on the entire application. Moreove ...
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- Linux 查找一个函数在哪调用
grep "function has" -R ThinkPHP
- Redis命令-HyperLogLog
HyperLogLog数据结构简单介绍 能够看http://www.cnblogs.com/ysuzhaixuefei/p/4052110.html 博客,介绍的相对照较清晰. HyperLogLo ...
- gwt学习资料
学习资料: 2 3
- c6----函数的声明和实现
// // main.c // 函数的声明和定义 // // Created by xiaomage on 15/6/7. // Copyright (c) 2015年 xiaomage. All r ...
- HttpClient连接超时及读取超时
HttpClient连接超时及读取超时 httpClient在执行具体http请求时候 有一个连接的时间和读取内容的时间: HttpClient连接时间 所谓连接的时候 是HttpClient发送请求 ...
- js 转化为几天前,几小时前,几分钟前...
转换标准时间为时间戳: function getDateTimeStamp(dateStr){ return Date.parse(dateStr.replace(/-/gi,"/" ...
- python中黏包现象
#黏包:发送端发送数据,接收端不知道应如何去接收造成的一种数据混乱现象. #关于分包和黏包: #黏包:发送端发送两个字符串"hello"和"word",接收方却 ...
- Fragment间相互调用并传值
public class MainFragment extends Fragment { private static final String ARG_DATE="com.example. ...