Ai
1 Star 0 Fork 0

Shawy/2023Linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ProdCon.cc 684 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shawy 提交于 2023-04-26 15:17 +08:00 . ThreadPool Test1
#include <iostream>
#include "ThreadPool.hpp"
#include "Task.hpp"
#include <sys/types.h>
// #include "Task.hpp"
// 主线程
int opt = -1;
int main()
{
srand((unsigned long)time(nullptr) ^ getpid() ^ 0x3f3f3f3f);
ThreadPool<Task>* tp = new ThreadPool<Task>(); // 创建线程池对象
tp->run(); // 创建线程
while(1)
{
opt = rand() % 2;
int x = rand() % 10 + 1;
int y = rand() % 5 + 1;
Task task(x, y, sol[opt]);
// 将任务放到线程池中
tp->pushTask(task);
if(opt) std::cout << "生产者线程: " << x << "-" << y << "= _?_" << std::endl;
else std::cout << "生产者线程: " << x << "+" << y << "= _?_" << std::endl;
sleep(1);
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/shawyxy/2023-linux.git
git@gitee.com:shawyxy/2023-linux.git
shawyxy
2023-linux
2023Linux
main

搜索帮助