/** @file  packaged_task.cpp
* @note
* @brief
* @author
* @date 2019-8-15
* @note
* @history
* @warning
*/
// packaged_task example
#include <iostream> // std::cout
#include <future> // std::packaged_task, std::future
#include <chrono> // std::chrono::seconds
#include <thread> // std::thread, std::this_thread::sleep_for // count down taking a second for each value:
int countdown (int from, int to) {
for (int i=from; i!=to; --i) {
std::cout << i << '\n';
std::this_thread::sleep_for(std::chrono::milliseconds());
}
std::cout << "Lift off!\n";
return from-to;
} int main ()
{
std::packaged_task<int(int,int)> tsk (countdown); // set up packaged_task
std::future<int> ret = tsk.get_future(); // get future std::thread th (std::move(tsk),,); // spawn thread to count down from 10 to 0 // ... int value = ret.get(); // wait for the task to finish and get result std::cout << "The countdown lasted for " << value << " seconds.\n"; th.join(); return ;
}

最新文章

  1. luaprofiler探索
  2. iOS 圆角图片
  3. 12. Linux在线升级yum
  4. HDU 3400 Line belt【三分套三分】
  5. FJNU 1152 Fat Brother And Integer(胖哥与整数)
  6. LINUX HOOK
  7. 2015第10周五CSS—2
  8. osgearth earth文件规范-符号参考
  9. c++ 类的默认八种函数
  10. Python——Flask框架——程序的结构
  11. kali渗透测试之缓冲区溢出实例-windows,POP3,SLmail
  12. ftok()函数深度解析
  13. 成功安装的Sublime Text3
  14. 洛谷.4717.[模板]快速沃尔什变换(FWT)
  15. Always an integer UVALive - 4119
  16. Cisco HSRP 配置方法(热备份路由协议)配置实例
  17. hdu 1966 Pie
  18. python学习:数据类型检查
  19. Python之协程(coroutine)
  20. Android:反编译apk

热门文章

  1. mongodb移除分片和添加分片(转)
  2. 17、Learning and Transferring IDs Representation in E-commerce笔记
  3. JS数组扁平化(flat)
  4. web scraper——爬取知乎|微博用户数据模板【三】
  5. C++定义和初始化数组以及memset的使用(转)
  6. B君的历史——复数乘法&amp;&amp;爆搜
  7. VSFTPD匿名用户上传文件
  8. 按值传递与按值引用详解(java版)
  9. WinDbg常用命令系列---.effmach
  10. 小数据池/is和==/再谈编码作业