packaged_task
2024-10-21 06:09:15
/** @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 ;
}
最新文章
- luaprofiler探索
- iOS 圆角图片
- 12. Linux在线升级yum
- HDU 3400 Line belt【三分套三分】
- FJNU 1152 Fat Brother And Integer(胖哥与整数)
- LINUX HOOK
- 2015第10周五CSS—2
- osgearth earth文件规范-符号参考
- c++ 类的默认八种函数
- Python——Flask框架——程序的结构
- kali渗透测试之缓冲区溢出实例-windows,POP3,SLmail
- ftok()函数深度解析
- 成功安装的Sublime Text3
- 洛谷.4717.[模板]快速沃尔什变换(FWT)
- Always an integer UVALive - 4119
- Cisco HSRP 配置方法(热备份路由协议)配置实例
- hdu 1966 Pie
- python学习:数据类型检查
- Python之协程(coroutine)
- Android:反编译apk
热门文章
- mongodb移除分片和添加分片(转)
- 17、Learning and Transferring IDs Representation in E-commerce笔记
- JS数组扁平化(flat)
- web scraper——爬取知乎|微博用户数据模板【三】
- C++定义和初始化数组以及memset的使用(转)
- B君的历史——复数乘法&;&;爆搜
- VSFTPD匿名用户上传文件
- 按值传递与按值引用详解(java版)
- WinDbg常用命令系列---.effmach
- 小数据池/is和==/再谈编码作业