1 Star 0 Fork 0

被抓哋尒蓅氓/ThreadPool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
example.cpp 633 Bytes
一键复制 编辑 原始数据 按行查看 历史
#include <iostream>
#include <vector>
#include <chrono>
#include "ThreadPool.h"
int main()
{
ThreadPool pool(4);
std::vector< std::future<int> > results;
for(int i = 0; i < 8; ++i) {
results.emplace_back(
pool.enqueue([i] {
std::cout << "hello " << i << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "world " << i << std::endl;
return i*i;
})
);
}
for(auto && result: results)
std::cout << result.get() << ' ';
std::cout << std::endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/perfyperfect/ThreadPool.git
git@gitee.com:perfyperfect/ThreadPool.git
perfyperfect
ThreadPool
ThreadPool
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385