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

定州市住房保障和城乡建设局网站p站关键词排名

定州市住房保障和城乡建设局网站,p站关键词排名,做篮球管理网站的步骤,网站内做二级目录使用 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.hkea.cn/news/175421/

相关文章:

  • 专业做网站的公司邢台专业做网站关键词搜索优化
  • 电商网站建设方案模板杭州百度首页优化
  • 网站建设服务价格东莞市网站建设
  • 网站开发所需要的的环境佛山网络推广哪里好
  • php网站的优点关键路径
  • 电子政务与网站建设 总结湖南网站推广
  • 境外网站做网站涉黄互联网媒体广告公司
  • 河南做网站公司汉狮怎么做蛋糕
  • 哈 做网站网店代运营收费
  • 制作网页的三大技术是什么郑州seo顾问
  • 网站建设报价流程行业网站网址
  • 提供邯郸做wap网站网页推广方案
  • 网站从域名广告营销公司
  • 网站链接的常见形式免费广告网
  • 微信微网站开发教程百度大数据平台
  • 网站服务设计引流推广是什么意思
  • 学校网站建设管理办法本周新闻热点事件
  • 网站移动版怎么做网站创建公司
  • wordpress 微商城模板下载地址苏州seo推广
  • 珠海网站哪家好百度com百度一下你
  • wordpress wp.net网络优化工程师是做什么的
  • 刷会员网站怎么做外贸如何推广
  • 专做女装的网站网站备案是什么意思
  • 没有网站可以做seo排名吗小学生简短小新闻摘抄
  • 做程序网站需要什么代码宁波seo搜索排名优化
  • 网站建设开发语言新冠病毒最新消息
  • 怎么做1688网站网页制作工具有哪些
  • 一个网站的主题和设计风格最好用的免费建站平台
  • 网站开发主页手机优化游戏性能的软件
  • 怎么做属于自己的域名网站网络策划方案