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

靖江有哪些做网站的免费网站可以下载

靖江有哪些做网站的,免费网站可以下载,网站长尾关键词,大良网站建设公司使用 condition_variable::wait(unique_lock<mutex>&lck, Predicate pred) 时&#xff0c;必须保证条件变量通过notify唤醒的同时&#xff0c;wait 的第二个参数 Predicate 返回 true 了才可以往下走。必须两个条件同时满足&#xff0c;如果notify的时候Predicate返回…

 使用 condition_variable::wait(unique_lock<mutex>&lck, Predicate pred) 时,必须保证条件变量通过notify唤醒的同时,wait 的第二个参数 Predicate 返回 true 了才可以往下走。必须两个条件同时满足,如果notify的时候Predicate返回时false一样的唤不醒线程。

#include <iostream>
#include <future>
#include <chrono>
#include <string>
#include<functional>
#include <queue>using Task = std::function<void()>;
class ThreaPool
{
public:void start() {running_ = true;}bool is_running(){return running_;}void stop() {std::cout << "stop..." << std::endl;running_ = false;std::unique_lock<std::mutex> lk(qmutext_);tasks_.push([]() { std::cout << "hello pool end " << std::endl;  });cond_.notify_all();}void push_task(Task task) {if (!running_){return;}std::unique_lock<std::mutex> lk(qmutext_);tasks_.push(task);cond_.notify_one();}ThreaPool(int count){for (int i = 0; i < count; i++){pool_.emplace_back([this]() {while (true){Task task;{std::unique_lock<std::mutex> lk(qmutext_);std::cout << "wait 1" << std::endl;cond_.wait(lk, [this] {return !running_ || !tasks_.empty(); });std::cout << "wait 2" << std::endl;if (!tasks_.empty()){task = std::move(tasks_.front());tasks_.pop();}}if (task){task();}if (!this->is_running()){std::cout << "stoped 1" << std::endl;std::unique_lock<std::mutex> lk(qmutext_);if (tasks_.empty()) {std::cout << "stoped 2" << std::endl;return;}}}});}}~ThreaPool() {for (std::thread& worker : pool_) {worker.join();}};private:std::vector<std::thread> pool_;std::mutex qmutext_;std::condition_variable cond_;std::queue< Task > tasks_;std::atomic_bool running_{ true };
};int main()
{ThreaPool pool(5);std::this_thread::sleep_for(std::chrono::seconds(1));pool.push_task([]() { std::cout << "hello pool 1 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 2 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 3 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 4 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 5 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 6 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 7 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 8 \n" << std::endl;  });pool.push_task([]() { std::cout << "hello pool 9 \n" << std::endl;  });std::this_thread::sleep_for(std::chrono::seconds(1));pool.stop();return 0;
}

http://www.yayakq.cn/news/822796/

相关文章:

  • 济南网站优化推广方案广州市官方网站
  • 网站要有可留言功能 怎么做全国学校信息查询官网
  • 云服务器怎么做网站wordpress 获得参数
  • 关于建设网站的申请常州免费建站
  • 国外 家具 网站模板root.txt文件放到您网站的根目录下
  • 阿里云备案增加网站泰州企业自助建站
  • 网站开发的工资是多少如何做外贸品牌网站
  • 福州执业建设中心网站网站开发发帖语言
  • 网站后缀是xyz指得是什么行唐网站建设
  • 怎么免费搭建一个网站wordpress仿站工具
  • 上海企业网站建设费用网站建设行业
  • 百度搜索网站介绍南京刚刚发生的大事
  • 提供手机网站制作公司威县做网站哪儿便宜
  • 佛山专业网站建设团队品牌策划与推广方案
  • 黄骅市网站建设设计旅游网站的主色调
  • 电商网站建设代码大全微商分销系统怎么做
  • 设计很好看的网站佛山建站专家
  • 电子商务个人网站可以备案吗中国机械加工制造网
  • 做网站赚几百万网站后台是怎样制作的
  • 门户网站建站注意事项领先的响应式网站建设平台
  • 百度地图3d实景地图优化网站的步骤
  • 关于电商网站的数据中心建设方案网站建设有几种工具
  • 公司名字大全参考2023南昌网站seo技术
  • 武昌网站制作建设varnish 4.0 wordpress
  • 建筑工人招聘网站怎么做360建站官网
  • 发布出租信息免费的网站找个人给我做电影网站好
  • 骆诗网站建设天津室内设计公司排行
  • 邢台手机网站建设价格wordpress 图片被缩小
  • 魔立方 网站建设永修建设局网站
  • 网站规划与建设论文c 开发商城网站开发