当前位置: 首页 > news >正文

做网站打广告图片素材北京网站建设认知

做网站打广告图片素材,北京网站建设认知,烟台网站定制排名,opencms wordpress线程池可以有效地管理和重用线程资源#xff0c;避免频繁创建和销毁线程带来的开销。以下是一个简单的线程池示例。 cpp #include iostream #include vector #include thread #include queue #include mutex #include condition…线程池可以有效地管理和重用线程资源避免频繁创建和销毁线程带来的开销。以下是一个简单的线程池示例。 cpp #include iostream #include vector #include thread #include queue #include mutex #include condition_variable #include functionalclass ThreadPool { public:ThreadPool(size_t numThreads);~ThreadPool();void enqueue(std::functionvoid() func);private:std::vectorstd::thread workers;std::queuestd::functionvoid() tasks;std::mutex queueMutex;std::condition_variable condition;bool stop;void worker(); };ThreadPool::ThreadPool(size_t numThreads) : stop(false) {for (size_t i 0; i numThreads; i) {workers.emplace_back([this] { this-worker(); });} }ThreadPool::~ThreadPool() {{std::unique_lockstd::mutex lock(queueMutex);stop true;}condition.notify_all();for (std::thread worker : workers) {worker.join();} }void ThreadPool::enqueue(std::functionvoid() func) {{std::unique_lockstd::mutex lock(queueMutex);tasks.push(func);}condition.notify_one(); }void ThreadPool::worker() {while (true) {std::functionvoid() task;{std::unique_lockstd::mutex lock(queueMutex);condition.wait(lock, [this] { return this-stop || !this-tasks.empty(); });if (this-stop this-tasks.empty()) return;task std::move(this-tasks.front());this-tasks.pop();}task();} }// 示例使用 void exampleTask(int n) {std::cout Task n is being processed by thread std::this_thread::get_id() std::endl;std::this_thread::sleep_for(std::chrono::seconds(1)); }int main() {ThreadPool pool(4); // 创建具有4个线程的线程池for (int i 0; i 10; i) {pool.enqueue([i] { exampleTask(i); });}在这里插入代码片std::this_thread::sleep_for(std::chrono::seconds(5)); // 保证主线程等待足够长的时间让线程池处理完任务return 0; }
http://www.hkea.cn/news/14525194/

相关文章:

  • 域名注册网站免费网站排名应该怎么做
  • 如何给网站做关键字怎么找网站站长
  • 重庆中小企业网站建设公司ppt哪个网站做的好
  • 湖南宁乡建设局网站两学一做微网站交流
  • 个人网站方案建设书网站seo快速优化
  • 网站建设要哪些seo网络软件开发专业是做什么的
  • 网站建设优化服务策划响应式网站建设准备
  • 山东省建设工程质量监督总站网站网页设计模板图片
  • 网站名称填写什么深圳高端设计公司名单
  • 简单的网站源码新东方烹饪学校学费价目表
  • 为什么要建设门户网站长兴县建设局网站
  • 网络维护网站美工惠州网站建设哪家强
  • 加盟网网站建设标签下载wordpress
  • php做的静态网站怎么加密个人智慧团建系统登录
  • 有口碑的番禺网站建设ui设计职业培训机构
  • 建网站解决方案seo网站推广价格
  • 专门做网站的公司与外包公司有哪些新乡市工程建设信息网
  • 自己怎么做网站优化西安手机网站建设公司排名
  • 佛山建网站哪家好网站网站开发逻辑
  • cms建站仓储网站开发
  • 成都营销型网站建设公司广州新闻报道
  • 做 个收废品网站做百度推广怎么做才能有电话
  • 有哪些网站做的很好wordpress压缩数据库查询
  • 网站建设需要材料关于旅游案例的网站
  • 建设部网站投诉如何注册遵义住房和城乡建设局网站
  • 如何在学校网站上做链接免费公司介绍网站怎么做
  • 经典网站赏析信息化工作总结 网站建设
  • 嵊州建设银行取款网站大兴建设网站公司
  • 佛山做推广网站的怎样推广才能让更多人看到
  • 网站未收录wordpress图片文件夹更换