当前位置: 首页 > news >正文

江门网站建设方案三亚市建设局官方网站

江门网站建设方案,三亚市建设局官方网站,打开网站后直接做跳转页面吗,seo优化师一#xff1a;概述 C11引入了thread类#xff0c;大大降低了多线程使用的复杂度#xff0c;原先使用多线程只能用系统的API#xff0c;无法解决跨平台问题#xff0c;一套代码平台移植#xff0c;对应多线程代码也必须要修改。现在在C11中只需使用语言层面的thread可以解…一概述 C11引入了thread类大大降低了多线程使用的复杂度原先使用多线程只能用系统的API无法解决跨平台问题一套代码平台移植对应多线程代码也必须要修改。现在在C11中只需使用语言层面的thread可以解决这个问题。 所需头文件thread 二构造函数 1.默认构造函数 thread() noexcept一个空的std::thread执行对象 2.初始化构造函数 templateclass Fn, class... Argsexplicit thread(Fn fn, Args... args);创建std::thread执行对象线程调用threadFun函数函数参数为args。 1 void threadFun(int a) 2 { 3 cout this is thread fun ! endl; 4 } 5 6 thread t1(threadFun, 2); 3.拷贝构造函数 thread(const thread) delete;拷贝构造函数被禁用std::thread对象不可拷贝构造 1 void threadFun(int a) 2 { 3 cout this is thread fun ! endl; 4 } 5 6 int value 2; 7 thread t1(threadFun, std::ref(value)); 4.Move构造函数 thread(thread x)noexcept调用成功原来x不再是std::thread对象 1 void threadFun(int a) 2 { 3 cout this is thread fun ! endl; 4 } 5 6 int value 2; 7 thread t1(threadFun, std::ref(value)); 8 thread t2(std::move(t1)); 9 t2.join(); 三成员函数 1.get_id() 获取线程ID返回类型std::thread::id对象。 1 thread t1(threadFun);2 thread::id threadId t1.get_id();3 cout 线程ID threadId endl;4 5 //threadId转换成整形值所需头文件sstream6 ostringstream oss;7 oss t1.get_id();8 string strId oss.str();9 unsigned long long tid stoull(strId); 10 cout 线程ID tid endl; 2.join() 创建线程执行线程函数调用该函数会阻塞当前线程直到线程执行完join才返回。 thread t1(threadFun); t1.join() //阻塞等待 3.detach() detach调用之后目标线程就成为了守护线程驻留后台运行与之关联的std::thread对象失去对目标线程的关联无法再通过std::thread对象取得该线程的控制权。 4.swap() 交换两个线程对象 1 thread t1(threadFun1); 2 thread t2(threadFun2); 3 cout 线程1的ID t1.get_id() endl; 4 cout 线程2的ID t2.get_id() endl; 5 6 t1.swap(t2); 7 8 cout 线程1的ID t1.get_id() endl; 9 cout 线程2的ID t2.get_id() endl; 5.hardware_concurrency() 获得逻辑处理器储量,返回值为int型  1 int coreNum thread::hardware_concurrency();  四使用  1.创建线程 1 void threadFun1()2 {3 cout this is thread fun1 ! endl;4 }5 6 int main()7 {8 thread t1(threadFun1);9 t1.join(); 10 11 getchar(); 12 return 1; 13 } 2.创建线程传参 1 void threadFun1(int v)2 {3 cout this is thread fun1 ! endl;4 cout v endl;5 }6 7 int main()8 {9 int value 6; 10 thread t1(threadFun1, value); 11 t1.join(); 12 13 getchar(); 14 return 1; 15 } 需要注意变量int value 和int v 做变量传递时并不是引用而是对变量做了拷贝所以在传递给int v前int value不能出作用域(释放了内存)join()可以保证int value变量释放内存如果使用detach()可能存在这种情况。 3.创建线程引用传参 1 void threadFun1(int v)2 {3 cout this is thread fun1 ! endl;4 cout v endl;5 }6 7 int main()8 {9 int value 6; 10 thread t1(threadFun1, std::ref(value)); 11 t1.join(); 12 13 getchar(); 14 return 1; 15 } 4.创建建线程线程函数为类成员函数 1 class Object2 {3 public:4 Object()5 {6 cout 构造函数 endl;7 }8 9 ~Object() 10 { 11 cout 析构函数 endl; 12 } 13 14 void fun(string info) 15 { 16 cout info endl; 17 } 18 19 }; 20 21 int main() 22 { 23 24 Object obj; 25 string str 我是一个类的成员函数; 26 thread t1(Object::fun, obj, str); 27 t1.join(); 28 29 getchar(); 30 return 1; 31 }   扫码关注公众号 专注分享C/CC(11,14,17)STLJavaSpringmybatismysqlredis分布式高并发设计模式爬虫dockershell编程等相关技术还有高薪互联网职位内推在这里一起探讨一起学习一起进步同时不定期分享视频书籍资源充分利用碎片化时间让我们的技术之路更加有乐趣转载于:https://www.cnblogs.com/woniu201/p/10145044.html
http://www.huolong8.cn/news/102762/

相关文章:

  • 深圳企业网站建设电话怎么修改wordpress目录名字
  • 安亭做网站公司网站上做网上支付功能
  • 大学生旅游网站设计框架装饰工程网站模板下载
  • 广告图片网站源码自己做头像的网站漫画
  • 做网站 数据库做网站效果图总结
  • 网站开发需要技术seo深度优化外包
  • 做网站手机端需要pc端的源代码吗企业培训网站
  • 网站增值业务域名权重查询
  • 做网站常用的插件网站建设确认报告
  • 手机做网站空间宝安电子厂做网站
  • 城乡与建设厅网站首页如何做网站的登录注册
  • 公司制作一个网站价格公司品牌策划设计
  • 12380网站开发想做个自己的网站
  • 网站收录突然全部没有了欧派家居全屋定制价格多少钱一平
  • 广州企业网站seo定制开发公司
  • 做公司网站要钱吗济南如何挑选网站建设公司
  • 家具网站开发设计论文wordpress怎么降级
  • 淄博手机网站常熟滨江开发区人才网
  • 建站宝盒建站系统网站优化 前端怎么做
  • 网站设计项目总结网站开发主管岗位职责
  • 邯郸网站建设效果学校网站html模板
  • 取消网站备案时间素材网
  • 开普网站建设公司网站专题模板
  • 企业建网站程序凡科邮箱
  • 上海网站建设哪家公司好淘宝店采用哪些方法做网站推广
  • 龙岗 网站建设深圳信科成都网站建设 外包
  • 职业技能培训网站在什么网站上可以做免费广告
  • 做电影网站怎样赚钱wordpress aspnet_client
  • 网站建设错误代码50019网络建设与网站建设
  • 制作钓鱼网站的费用大连能做网站的公司有