代码拉取完成,页面将自动刷新
https://gitee.com/TristanHNU/thread-pool.git
基于 C++ 17 的线程池
linux
sudo apt install build-essential gdb cmake git curl
windows
1、open shell to install chocolatey (need proxy
$Env:http_proxy="http://127.0.0.1:7890"
$Env:https_proxy="http://127.0.0.1:7890"
)
在powershell中安装chocolatey (https://community.chocolatey.org/packages/cmake.install)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install mingw --installargs 'ADD_MINGW_TO_PATH=System'
choco install cmake.install
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
example
// Create a thread pool with 4 worker threads
ThreadPool pool(4);
// Enqueue some tasks
std::vector<std::future<int>> results;
for (int i = 0; i < 50; i++)
{
results.emplace_back(
pool.enqueue([i]
{
std::cout << "Hello from task " << i << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "Task " << i << " completed" << std::endl;
return i * i; }));
}
// Wait for all tasks to complete
for (auto &result : results)
std::cout << "Task completed with result: " << result.get() << std::endl;
return 0;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。