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

微信网站怎么做的陕西省住房建设厅官网

微信网站怎么做的,陕西省住房建设厅官网,王也为什么这么受欢迎,wordpress 响应式菜单目录 1--std::async的使用 2--std::packaged_task的使用 3--std::promise的使用 1--std::async的使用 std::async用于启动一个异步任务#xff0c;并返回一个std::future对象#xff1b;std::future对象里含有异步任务线程入口函数的结果#xff1b; std::launch::deferr…目录 1--std::async的使用 2--std::packaged_task的使用 3--std::promise的使用 1--std::async的使用 std::async用于启动一个异步任务并返回一个std::future对象std::future对象里含有异步任务线程入口函数的结果         std::launch::deferred 表示调用线程入口函数将会被延迟到 std::future 的 wait() 或 get() 调用当 wait() 或者 get() 没有被调用时线程入口函数不会被调用(线程不会被创建) #include iostream #include thread #include mutex #include futureclass Sample{ public:// 线程入口函数int thread(int value){std::cout thread id: std::this_thread::get_id() std::endl;std::chrono::microseconds dura(value); // reststd::this_thread::sleep_for(dura);return 5;}};int main(int argc, char *argv[]){Sample sample;int value 5000;// std::async用于启动一个异步任务并返回一个std::future对象// std::future对象里含有异步任务线程入口函数的结果std::cout thread id: std::this_thread::get_id() std::endl;std::futureint result std::async(Sample::thread, sample, value);// std::launch::deferred 表示调用线程入口函数将会被延迟到 std::future 的wait()或get()调用// 当wait()或者get()没有被调用时线程入口函数不会被调用(线程不会被创建)// std::futureint result std::async(std::launch::deferred, Sample::thread, sample, value);// result.get()等待thread()执行完毕获取结果后主线程才继续往下执行std::cout resule.get(): result.get() std::endl; // result.wait() // 等待线程返回但不返回结果std::cout main thread continue ... std::endl;return 0; } 2--std::packaged_task的使用 std::packaged_task 用于打包任务其包装各种可调用对象方便后续作为线程入口函数 #include iostream #include thread #include mutex #include future// 线程入口函数 int thread(int value){std::cout thread id: std::this_thread::get_id() std::endl;std::chrono::microseconds dura(value); // reststd::this_thread::sleep_for(dura);return 5; }int main(int argc, char *argv[]){// std::packaged_task 用于打包任务其包装各种可调用对象方便后续作为线程入口函数std::cout thead id: std::this_thread::get_id() std::endl;std::packaged_taskint(int) mypt(thread);int value 5000;std::thread thread1(std::ref(mypt), value);thread1.join();std::futureint result mypt.get_future();std::cout result.get(): result.get() std::endl;return 0; } 3--std::promise的使用 std::promise 用于在其他线程中使用某个线程中的值在下面的实例代码中thread2 使用了 thread1 中的 result 值 #include iostream #include thread #include mutex #include future// 线程入口函数 int thread(std::promiseint tmpp, int clac){clac;clac * 10; std::cout thread id: std::this_thread::get_id() std::endl;int result clac;tmpp.set_value(result);return 0; }void thread_2(std::futureint tmpf){auto result2 tmpf.get();std::cout tmpf.get(): result2 std::endl; }int main(int argc, char *argv[]){// std::promise 用于在某个线程中赋值并在其他线程中将值取来用std::cout thead id: std::this_thread::get_id() std::endl;std::promiseint prom; int clac 1;std::thread thread1(thread, std::ref(prom), clac);thread1.join();// 将promise中的值取来用std::futureint result prom.get_future();std::thread thread2(thread_2, std::ref(result));thread2.join();return 0; }
http://www.hkea.cn/news/14565636/

相关文章:

  • 移动互联网站开发昆山建设工程招聘信息网站
  • 网站建设合约具体内容wordpress 主题 设计
  • 厦门网站建设培训机构群晖 wordpress 阿里云
  • 南昌市建设工程质量监督网站wordpress 表单 采集
  • 网站被别人做了跳转天元建设集团有限公司张桂玉
  • 网站建设目的及功能定位网站建设好如何开通
  • 学习完成网站建设作业贵阳网站建设hsyunso
  • 威海城乡建设局网站郑州宣传片制作
  • 玉林做网站公司开发一个app价格
  • 医疗网站建设哪家好做淘宝客网站需要备案吗
  • 深圳网站设计九曲开发工具选项卡在哪
  • 电脑做视频的网站wap网站建设公司
  • 易橙云做的网站怎么样十大素材网站
  • wordpress 调用站外api电子商务网站建设需求
  • 做餐饮酒店网站肇庆城乡建设网站
  • 做教育网站挣钱网络工程解决方案公司
  • 邢台做网站优化网站建设 应该付多少维护费呢
  • 网站建设技术标书苏州学做网站
  • 绿色大气网站艺术设计专业灵感推荐网站
  • 网站开发原始数据鲅鱼圈网站建设
  • 做国内学历公证的网站徐州做网站哪里好
  • 网站建设邯郸做网站公司大型
  • 重庆站外推广网站重庆网站制作公司多少钱
  • 易企推做seo要明白网站
  • 用html编写淘宝网站怎么做自己建设网站在哪里建设
  • 网站优化改动怎么做制作深圳网站建设
  • 满屏网站设计做多大订单查询网站怎么做
  • 跨境电商平台网站建设多少钱未成年做网站
  • 大连建网站需要多少钱网站下载地址
  • 做代理稳妥的彩票网站有哪些wordpress移动化