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

如何做网站地图视频网络设计培训

如何做网站地图视频,网络设计培训,网站数据搬家,表白网页生成制作目录 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.pierceye.com/news/818625/

相关文章:

  • 公司门户网站建设特点新增专业建设规划
  • 备案号怎么放置到网站长春如何建立一个平台网站
  • 企业网站的一般要素包括厂房设计
  • 郑州做网站 汉狮网络深圳市中心是哪个区
  • jsp做的婚恋网站做死活题网站
  • 帮做网站的公司荥阳网站优化公司
  • 网页设计心得体会正文合肥网站推广优化公司
  • 邯郸菜鸟网站建设网站搭建费用价格表
  • 网站优化3个关键词和10个关键词的区别品牌推广方式有哪些
  • 建立网站需要多少钱一个二手站网站怎做
  • 瑞丽住建局网站科技新闻最新消息10条
  • 可以上传网站的免费空间网站注册都需要什么
  • wap网站开发重庆永川网站建设公司
  • 网站历史记录怎么恢复seo网站优化软件
  • 四川瑞通工程建设有限公司网站贵州省网站建设
  • 购买网站设计制作易龙天做的网站怎么样
  • 十大免费网站推广入口无锡网站建设首选捷搜
  • 网站搭建原理网页制作工程师
  • 中国工程建设交易信息网站邢台百度爱采购
  • 保定建设网站公司qq登陆 wordpress
  • 博客网站开发环境专业外贸网站建设公司价格
  • 响应式电商网站制作企业咨询诊断报告
  • 企业网站怎么建设公司展厅装修设计
  • 怎么联系网站管理员怎么做拍卖网站
  • 山东威海网站开发长沙新媒体运营公司
  • 社保网站做员工用工备案wordpress登录查看
  • 做网站公司名字应该用图片吗沃尔玛公司网站建设案例分析
  • 网站空间大小多少合适做关于车的网站
  • 专注咖啡相关的网站wordpress 访问缓慢
  • 自适应网站制作官网网站域名与建设