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

餐饮网站建设设计制作网站的软件叫什么

餐饮网站建设设计,制作网站的软件叫什么,家装商城系统网站建设,网站备案申请流程目录 1--std::async的使用 2--std::packaged_task的使用 3--std::promise的使用 1--std::async的使用 std::async用于启动一个异步任务,并返回一个std::future对象;std::future对象里含有异步任务线程入口函数的结果; 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 <future>class 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::future<int> result = std::async(&Sample::thread, &sample, value);// std::launch::deferred 表示调用线程入口函数将会被延迟到 std::future 的wait()或get()调用// 当wait()或者get()没有被调用时,线程入口函数不会被调用(线程不会被创建)// std::future<int> 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_task<int(int)> mypt(thread);int value = 5000;std::thread thread1(std::ref(mypt), value);thread1.join();std::future<int> 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::promise<int> &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::future<int> &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::promise<int> prom; int clac = 1;std::thread thread1(thread, std::ref(prom), clac);thread1.join();// 将promise中的值取来用std::future<int> result = prom.get_future();std::thread thread2(thread_2, std::ref(result));thread2.join();return 0;
}

http://www.dinnco.com/news/52150.html

相关文章:

  • 建立网站一般包括什么等方式百度知道首页登录入口
  • 租赁服务器的网站电商网站开发平台有哪些
  • 武汉网站建设公司哪家好百度seo排名工具
  • 哪个网站可以做教师招聘题目网站是否含有seo收录功能
  • 专门做油画交流的网站中国重大新闻
  • 盐山网站制作竞价点击软件排名
  • 网站制作图片滚动营销案例100例小故事及感悟
  • wordpress4.9 php版本惠州seo报价
  • 游戏网站建设与策划郴州网站建设网络推广平台
  • 网站开发需求分析主要内容优帮云排名优化
  • 网站用户体验诊断如何做友情链接
  • 在网站加上一个模块怎么做5118和百度指数
  • 石家庄新钥匙建站电商平台app大全
  • 日本人做的网站本子新东方英语线下培训学校
  • 网站制作哪家最好桔子seo工具
  • 南京百度网站建设品牌网络推广外包
  • 什么软件能创建网站正规教育培训机构
  • 营销网站做推广大数据网络营销
  • 随身wifi网站设置互联网产品营销策划方案
  • 郴州网签查询3分钟搞定网站seo优化外链建设
  • 企业做网站公司排名惠州抖音seo
  • 网站建设推广型手机百度网盘网页版登录入口
  • asp技术做网站引流用什么话术更吸引人
  • 慈善会的网站是形成还是建设企业网站建站模板
  • 烟台酒店网站建设注册一个网站
  • 制作装饰公司网站青岛做网站推广
  • 网站开发报价单.doc成都网站设计
  • 营业执照年审怎么年审关键词优化seo优化
  • jsp做网站前端实例网络营销策划方案怎么做
  • 长沙网站开发微联讯点不错培训教育