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

建立耐受什么意思/seo外包是什么意思

建立耐受什么意思,seo外包是什么意思,东莞东城网站建设,什么是网站版面布局测试了3种方式: 1:子线程不带返回值!! 2:子线程带返回值!! 3:子线程带引用类型参数!! 使用join方式,让父线程等待子线程运行结束. // TestTemp.cpp : 定义控制台应用程序的入口点。 //#include "stdafx.h&quo…

 测试了3种方式:

1:子线程不带返回值!!

2:子线程带返回值!!

3:子线程带引用类型参数!!

使用join方式,让父线程等待子线程运行结束.

// TestTemp.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include <vector>
#include <iostream>
#include <stdlib.h>#include <iostream>
#include<thread>
#include <ctime>
#include<chrono>
#include <thread>   //线程库using namespace std;volatile clock_t startt, endt;void  thread_task(void* para) 
{int *params = (int*)para;std::this_thread::sleep_for(std::chrono::seconds(params[0]));std::cout << "hello thread "<< std::this_thread::get_id()<< " paused " << params[0] << " seconds" <<",age:" << params[1] << std::endl;printf("free addr:0x%lx \n", params);delete[] params;
}int sum(int &x, int &y)
{printf("子线程id为:%d\n", std::this_thread::get_id());std::cout << std::hex << std::this_thread::get_id() << std::endl;std::this_thread::sleep_for(std::chrono::seconds(1));x += 100;y += 100;return x + y;
}int sums(int x, int y, int z)
{printf("子线程id为:%d\n", std::this_thread::get_id());std::this_thread::sleep_for(std::chrono::seconds(1));return x + y + z;
}int main()
{//子线程不带返回值//std::thread threads[5];std::cout << "创建 5 threads...\n";printf("子线程不带返回值!!\n");printf("主线程id:%d\n", std::this_thread::get_id());clock_t startt, endt;startt = clock();for (int i = 0; i < 5; ++i){int* para = new int[2];printf("malloc addr:0x%lx for thread\n", para);para[0] = i + 1;para[1] = 20 + i;threads[i] = std::thread(thread_task, (void*)para);}std::cout << "创建5个 threads完毕 ! Now wait for them to join \n";for (auto& t : threads) {t.join();//线程的活干完了,这个join()函数才能得到返回。父线程将会等待子线程们返回。}endt = clock();printf("All threads joined. cost:%u ms\n", endt - startt);//子线程不带返回值 end//printf("\n\n\n\n===============================================\n");//子线程带返回值//printf("子线程带返回值!!\n");printf("主线程id:%d\n", std::this_thread::get_id());int x = 3;int y = 4;int z = 5;int result = 0;std::thread t = std::thread([&] { result = sums(x, y, z); });t.join();printf("子线程返回值为:%d\n", result);//子线程带返回值 end//printf("\n\n\n\n===============================================\n");//子线程函数中有引用类型参数//printf("子线程带引用类型参数!!\n");printf("主线程id:%d\n", std::this_thread::get_id());//子线程函数中有引用类型参数 end//x = 3;y = 4;result = 0;std::thread t2 = std::thread([&] { result = sum(std::ref(x), std::ref(y)); });t2.join();printf("子线程执行完毕后,x:%d,y:%d,返回值为:%d\n", x, y, result);getchar();return 0;
}

运行结果:

创建 5 threads...
子线程不带返回值!!
主线程id:21716
malloc addr:0xd803c8 for thread
malloc addr:0xd80668 for thread
malloc addr:0xd80160 for thread
malloc addr:0xd80438 for thread
malloc addr:0xd804a8 for thread
创建5个 threads完毕 ! Now wait for them to join
hello thread 8324 paused 1 seconds,age:20
free addr:0xd803c8
hello thread 17044 paused 2 seconds,age:21
free addr:0xd80668
hello thread 16956 paused 3 seconds,age:22
free addr:0xd80160
hello thread 17312 paused 4 seconds,age:23
free addr:0xd80438
hello thread 21900 paused 5 seconds,age:24
free addr:0xd804a8
All threads joined. cost:5010 ms


===============================================
子线程带返回值!!
主线程id:21716
子线程id为:22080
子线程返回值为:12


===============================================
子线程带引用类型参数!!
主线程id:21716
子线程id为:15324
3bdc
子线程执行完毕后,x:103,y:104,返回值为:207

 

http://www.jmfq.cn/news/4863187.html

相关文章:

  • 企业做网站建设/北京网站优化校学费
  • 做网站哪里买空间好/广州seo关键词优化外包
  • 网络营销试题/关键词优化排名
  • 学生网站作品/北京网站seo哪家公司好
  • 定制网站建设服务/九江seo优化
  • 设计网站建设方案/百度认证官网
  • 国内做批发的网站/b站视频推广app
  • 做网站需要多少钱 网络服务/青岛网站关键词优化公司
  • 一元云购网站怎么做/seo点击排名器
  • 武汉p2p网站建设/cnzz
  • 网店网站建设哪家/seo入口
  • 沈阳中联做网站/怎么在百度推广自己的网站
  • 上海自助建站上海网站建设/茶叶网络营销策划方案
  • 做ppt的软件模板下载网站有哪些/百度推广代运营
  • 校园网站建设测试目的/无锡网站推广公司
  • 外贸网站设计的公司/营销策划培训
  • 网页设计与制作思考建议/seo搜索引擎优化试题
  • 怎么设置网站的logo/市场调研公司排名
  • 上海制造业企业100强/成都关键词优化排名
  • 余杭建设局网站/sem是什么意思职业
  • 做网站没有成本的方法/seo关键词优化如何
  • 怎样做网站分流赚钱/什么是seo是什么意思
  • wordpress主题缩略图不显示/百度seo培训
  • 一个网站怎么做软件好用/上海关键词优化推荐
  • 网站设计合同模板/长春网站制作计划
  • 广告设计公司制作/海外aso优化
  • 网站备案要几天/网络优化工程师有多累
  • 免费网站模板怎么用/百度手机助手
  • 临时工找工作网站做美缝/seo是什么意思seo是什么职位
  • 深圳做门户网站的网络公司/专业网站优化推广