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

海沧建设网站多少国外调色网站

海沧建设网站多少,国外调色网站,个人网页设计版面,本单位二级网站建设管理制度个人认为一个完备的定时器需要有如下功能#xff1a;在某一时间点执行某一任务在某段时间后执行某一任务重复执行某一任务N次#xff0c;任务间隔时间T那么如何实现定时器呢#xff1f;下面是我自己实现的定时器逻辑#xff0c;源码链接最后会附上。定时器中主要的数据结构… 个人认为一个完备的定时器需要有如下功能在某一时间点执行某一任务在某段时间后执行某一任务重复执行某一任务N次任务间隔时间T那么如何实现定时器呢下面是我自己实现的定时器逻辑源码链接最后会附上。定时器中主要的数据结构优先级任务队列队列中存储任务每个任务会添加时间戳最近的时间戳的任务会先出队。锁和条件变量当有任务需要执行时用于通知正在等待的线程从任务队列中取出任务执行。线程池各个任务会放在线程池中执行。下面是相关代码class TimerQueue {public:  struct InternalS {      std::chrono::time_pointstd::chrono::high_resolution_clock time_point_;      std::functionvoid() func_;      bool operator(const InternalS b) const { return time_point_ b.time_point_; }  };  enum class RepeatedIdState { kInit 0, kRunning 1, kStop 2 }; private:  std::priority_queuequeue_;  bool running_ false;  std::mutex mutex_;  std::condition_variable cond_;wzq::ThreadPool thread_pool_;std::atomicint repeated_func_id_;  wzq::ThreadSafeMapint, RepeatedIdState repeated_id_state_map_;}; 如何开启定时器功能打开内部的线程池功能用于执行放入定时器中的任务同时新开一个线程循环等待任务到来后送入线程池中执行。bool Run() {    bool ret thread_pool_.Start();    if (!ret) {        return false;    }    std::thread([this]() { RunLocal(); }).detach();    return true;} void RunLocal() {    while (running_) {        std::unique_lockstd::mutex lock(mutex_);        if (queue_.empty()) {            cond_.wait(lock);            continue;        }        auto s queue_.top();        auto diff s.time_point_ - std::chrono::high_resolution_clock::now();        if (std::chrono::duration_caststd::chrono::milliseconds(diff).count() 0) {            cond_.wait_for(lock, diff);            continue;        } else {            queue_.pop();            lock.unlock();            thread_pool_.Run(std::move(s.func_));        }    }} 如何在某一时间点执行任务根据时间戳构造InternalS放入队列中template typename F, typename... Args void AddFuncAtTimePoint(const std::chrono::time_pointstd::chrono::high_resolution_clock time_point, F f,                        Args... args) {    InternalS s;    s.time_point_ time_point;    s.func_ std::bind(std::forward(f), std::forward(args)...);    std::unique_lockstd::mutex lock(mutex_);    queue_.push(s);    cond_.notify_all();} 如何循环执行任务首先为这个循环任务生成标识ID外部可以通过ID来取消此任务继续执行代码如下内部以类似递归的方式循环执行任务。template typename R, typename P, typename F, typename... Argsint AddRepeatedFunc(int repeat_num, const std::chrono::duration time, F f, Args... args) {    int id GetNextRepeatedFuncId();    repeated_id_state_map_.Emplace(id, RepeatedIdState::kRunning);    auto tem_func std::bind(std::forward(f), std::forward(args)...);    AddRepeatedFuncLocal(repeat_num - 1, time, id, std::move(tem_func));    return id;} int GetNextRepeatedFuncId() { return repeated_func_id_; } template typename R, typename P, typename Fvoid AddRepeatedFuncLocal(int repeat_num, const std::chrono::duration time, int id, F f) {    if (!this-repeated_id_state_map_.IsKeyExist(id)) {        return;    }    InternalS s;    s.time_point_ std::chrono::high_resolution_clock::now() time;    auto tem_func std::move(f);    s.repeated_id id;    s.func_ [this, tem_func, repeat_num, time, id]() {        tem_func();        if (!this-repeated_id_state_map_.IsKeyExist(id) || repeat_num 0) {            return;        }        AddRepeatedFuncLocal(repeat_num - 1, time, id, std::move(tem_func));    };    std::unique_lockstd::mutex lock(mutex_);    queue_.push(s);    lock.unlock();    cond_.notify_all();} 声明本文于网络整理版权归原作者所有如来源信息有误或侵犯权益请联系我们删除或授权事宜。
http://www.pierceye.com/news/956633/

相关文章:

  • 企业型网站怎么做wordpress邮件服务器
  • 龙华网站(建设信科网络)网站建设哪家好推荐万维科技
  • 克拉玛依网站建设公司网站 正在建设中
  • 虚拟主机可以做视频网站嘛有哪些网站有收录做红酒的商行
  • 广州seo优化推广外贸网站优化谷歌关键词排名
  • 网络服务网站建设网站策划书包括哪些内容?
  • ps学做翻页相册网站wordpress导航图标
  • 模板网站的弊端在哪杨家平网站建设
  • 网站模板带手机站手表网站十大品牌
  • 物流网站功能设计师招聘网站有哪些
  • 知名网站开发哪里有重庆公司网站建设价格
  • 南头做网站公司重庆建设厂招聘信息网站
  • 网站建设的基本条件外贸建设网站制作
  • 移动电子商务平台就是手机网站奉化首页的关键词优化
  • 公司怎么建立一个网站展示型网站模板代码
  • 益阳网页设计十堰seo优化服务
  • discuz论坛建站教程微商城开发小程序开发
  • 饰品网站建设炫丽的网站
  • 网站建设制作介绍河南企业建站多站点管理系统
  • 网站盗号怎么做设计说明模板200字
  • 赣州人才网站搜索引擎广告是什么
  • 广州app开发网站建设与网站优化销售
  • 做淘客哪个网站好点如何做好网站建设销售
  • 手机端网站开发视频wordpress删除评论
  • 台州网站建设推广公司随州有哪些网站建设的公司
  • 定制商品的网站建设word超链接网站怎样做
  • 南昌做网站流程安徽省建设厅网站打不开
  • 雄安智能网站建设方案做涉黄的视频网站用什么服务器
  • 公司网站必须做可信认证吗免费关键词排名优化软件
  • 基金公司网站建设网站有哪几种