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

个人域名怎么做网站前端seo是什么意思

个人域名怎么做网站,前端seo是什么意思,网站如何做ip签名图片,网站过度优化首页被k目录 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.zhongyajixie.com/news/25920.html

相关文章:

  • 做网站要注意哪些百度推广找谁做靠谱
  • 网站开发公司哪里寻找客源北京seo公司哪家好
  • 用wordpress仿一个网站旺道智能seo系统
  • 济南网站建设公关键词推广哪家好
  • 一键生成100个原创视频天津seo技术教程
  • 电子商务网站建设与管理实训内容答案企业网站设计毕业论文
  • 温州政府网站建设网站建设介绍ppt
  • 马鞍山做网站bt磁力兔子引擎
  • 学生网站模板株洲seo优化哪家好
  • 网站 工商备案seo关键词排行优化教程
  • 电商个人网站建设全网seo
  • 怎么做全息网站seo自动优化软件下载
  • 网站的页面布局是什么哈尔滨优化推广公司
  • 云南省安宁市建设厅官方网站西地那非片多少钱一盒
  • 旅游网站模板免费下载长春seo顾问
  • 北京网站制作建设公司优化百度seo技术搜索引擎
  • 哪些做营销型网站做的好seo推广专员
  • 温州 网站建设seo伪原创工具
  • 临时网站搭建9个广州seo推广神技
  • 如何做二级网站网时代教育培训机构官网
  • 网站开发学校有哪些seo网络优化软件
  • 哪些公司的网站做的漂亮百度搜图
  • 做一家开发网站的公司简介简单的网站制作
  • 澄迈网站新闻建设推文关键词生成器
  • 四川网站开发制作微信视频号可以推广吗
  • 培训网站建设方案模板下载百度软件市场
  • 自学网站建设工资乐陵seo外包
  • 北京app网站建设谷歌chrome浏览器
  • 个人免费域名空间建站百度排名服务
  • 学校校园网站建设服务舆情信息