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

什么叫网站建设银行网站查询密码

什么叫网站,建设银行网站查询密码,视频网站上市公司有哪些,app网站开发成本C11中的std::async是个模板函数。std::async异步调用函数#xff0c;在某个时候以Args作为参数(可变长参数)调用Fn#xff0c;无需等待Fn执行完成就可返回#xff0c;返回结果是个std::future对象。Fn返回的值可通过std::future对象的get成员函数获取。一旦完成Fn的执行11中的std::async是个模板函数。std::async异步调用函数在某个时候以Args作为参数(可变长参数)调用Fn无需等待Fn执行完成就可返回返回结果是个std::future对象。Fn返回的值可通过std::future对象的get成员函数获取。一旦完成Fn的执行共享状态将包含Fn返回的值并ready。 std::async有两个版本 1.无需显示指定启动策略自动选择因此启动策略是不确定的可能是std::launch::async也可能是std::launch::deferred或者是两者的任意组合取决于它们的系统和特定库实现。 2.允许调用者选择特定的启动策略。 std::async的启动策略类型是个枚举类enum class launch包括 1. std::launch::async异步启动一个新的线程调用Fn该函数由新线程异步调用并且将其返回值与共享状态的访问点同步。 2. std::launch::deferred延迟在访问共享状态时该函数才被调用。对Fn的调用将推迟到返回的std::future的共享状态被访问时(使用std::future的wait或get函数)。 参数Fn可以为函数指针、成员指针、任何类型的可移动构造的函数对象(即类定义了operator()的对象)。Fn的返回值或异常存储在共享状态中以供异步的std::future对象检索。 参数Args传递给Fn调用的参数它们的类型应是可移动构造的。 返回值当Fn执行结束时共享状态的std::future对象准备就绪。std::future的成员函数get检索的值是Fn返回的值。当启动策略采用std::launch::async时即使从不访问其共享状态返回的std::future也会链接到被创建线程的末尾。在这种情况下std::future的析构函数与Fn的返回同步。 std::future介绍参考C11中std::future的具体使用方法_C 语言_脚本之家 详细用法见下面的测试代码下面是从其他文章中copy的测试代码部分作了调整详细内容介绍可以参考对应的reference #include iostream #include future #include chrono #include utility #include thread #include functional #include memory #include exception #include numeric #include vector #include cmath #include string #include mutexnamespace future_ {///// reference: http://www.cplusplus.com/reference/future/async/int test_async_1(){auto is_prime [](int x) {std::cout Calculating. Please, wait...\n;for (int i 2; i x; i){if (x%i 0){return false;}return true;}};// call is_prime(313222313) asynchronously:std::futurebool fut std::async(is_prime, 313222313);std::cout Checking whether 313222313 is prime.\n;// ...bool ret fut.get(); // waits for is_prime to returnif (ret) std::cout It is prime!\n;else std::cout It is not prime.\n;return 0;}///// reference: http://www.cplusplus.com/reference/future/launch/int test_async_2(){auto print_ten [](char c, int ms) {for (int i 0; i 10; i) {std::this_thread::sleep_for(std::chrono::milliseconds(ms));std::cout c;}};std::cout with launch::async:\n;std::futurevoid foo std::async(std::launch::async, print_ten, *, 100);std::futurevoid bar std::async(std::launch::async, print_ten, , 200);// async get (wait for foo and bar to be ready):foo.get(); // 注注释掉此句也会输出*bar.get();std::cout \n\n;std::cout with launch::deferred:\n;foo std::async(std::launch::deferred, print_ten, *, 100);bar std::async(std::launch::deferred, print_ten, , 200);// deferred get (perform the actual calls):bar.get();foo.get(); // 注注释掉此句则不会输出**********std::cout \n;return 0;}///// reference: https://en.cppreference.com/w/cpp/thread/asyncstd::mutex m;struct X {int testxx;void foo(int i, const std::string str) {std::lock_guardstd::mutex lk(m);std::cout str i \n;}void bar(const std::string str) {std::lock_guardstd::mutex lk(m);std::cout str \n;}int operator()(int i) {std::lock_guardstd::mutex lk(m);std::cout i \n;return i 10;}};template typename RandomItint parallel_sum(RandomIt beg, RandomIt end){auto len end - beg;if (len 1000)return std::accumulate(beg, end, 0);RandomIt mid beg len / 2;auto handle std::async(std::launch::async, parallel_sumRandomIt, mid, end);int sum parallel_sum(beg, mid);return sum handle.get();}int test_async_3(){std::vectorint v(10000, 1);std::cout The sum is parallel_sum(v.begin(), v.end()) \n;X x;x.testxx 8;// Calls (x)-foo(42, Hello) with default policy:// may print Hello 42 concurrently or defer executionauto a1 std::async(X::foo, x, 42, Hello);// Calls x.bar(world!) with deferred policy// prints world! when a2.get() or a2.wait() is calledauto a2 std::async(std::launch::deferred, X::bar, x, world!);// Calls X()(43); with async policy// prints 43 concurrentlyauto a3 std::async(std::launch::async, X(), 43);std::this_thread::sleep_for(std::chrono::seconds(2));a2.wait(); // prints world!std::cout a3.get() \n; // prints 53return 0;} // if a1 is not done at this point, destructor of a1 prints Hello 42 here///// reference: https://thispointer.com/c11-multithreading-part-9-stdasync-tutorial-example/int test_async_4(){using namespace std::chrono;auto fetchDataFromDB [](std::string recvdData) {// Make sure that function takes 5 seconds to completestd::this_thread::sleep_for(seconds(5));//Do stuff like creating DB Connection and fetching Datareturn DB_ recvdData;};auto fetchDataFromFile [](std::string recvdData) {// Make sure that function takes 5 seconds to completestd::this_thread::sleep_for(seconds(5));//Do stuff like fetching Data Filereturn File_ recvdData;};// Get Start Timesystem_clock::time_point start system_clock::now();std::futurestd::string resultFromDB std::async(std::launch::async, fetchDataFromDB, Data);//Fetch Data from Filestd::string fileData fetchDataFromFile(Data);//Fetch Data from DB// Will block till data is available in futurestd::string object.std::string dbData resultFromDB.get();// Get End Timeauto end system_clock::now();auto diff duration_cast std::chrono::seconds (end - start).count();std::cout Total Time Taken diff Seconds std::endl;//Combine The Datastd::string data dbData :: fileData;//Printing the combined Datastd::cout Data data std::endl;return 0;}} // namespace future_
http://wiki.neutronadmin.com/news/56897/

相关文章:

  • 企业网站前端模板网站开发售后服务
  • 电信ip做的网站移动不能访问凡科互动是做什么的
  • 网络营销管理师东莞关键词优化排名
  • 淘宝联盟做返利网站网站建设的目的与意义是什么
  • 深圳专业设计网站公司做网站的品牌公司
  • 荣成网站制作公司网站内页怎么做
  • php建设网站工具东莞玩具加工东莞网站建设
  • 做包装盒效果图的网站网站 建设 申请
  • 重庆旅游攻略必去景点推荐手机网络优化软件
  • 深圳企业企业网站建设安全教育网站建设背景
  • 大气手机网站模板网站流量是什么意思
  • 运城网站建设公司有多少怎么做网站作业
  • 常熟苏州网站建设做的新网站网上搜不到
  • 免费电子商务网站建设宁波手机网站制作
  • 常平网站公司科技企业网站源码
  • 基于php的网站开发流程图企业品牌宣传片制作
  • 博客类网站源码企业网站程序源码
  • 别人做网站要把什么要过来棋牌游戏网站怎么做
  • 律师网站 扁平化wordpress仿果壳
  • 网站服务器是什么意思公司做网站哪家好
  • 临猗做网站如何网上建设网站
  • 张家口网站建设价格制作ppt的软件手机版
  • 建设企业网站前市场分析做seo要明白网站内容
  • 网站的建设方法包括什么作用手机网站安全证书过期怎么处理
  • 网站建设公司首选国外免费域名网站
  • 中国网站建设公司前十名展示设计网站有哪些
  • 乐山企业网站建设免费下载微信
  • solusvm做网站网站建设工具有哪些品牌
  • 做网站需要花多少钱深圳网站优化效果
  • 个人微信注册网站支付宝网站开发文档