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

百度关键词首页排名怎么做网站的优化

百度关键词首页排名,怎么做网站的优化,wordpress怎么写html,郑州超凡装饰公司怎么样目录 基本概念 函数定义 函数实现与测试 测试1结果如下 测试2结果如下 基本概念 时间轮 是一种 实现延迟功能#xff08;定时器#xff09; 的 巧妙算法。如果一个系统存在大量的任务调度#xff0c;时间轮可以高效的利用线程资源来进行批量化调度。把大批量的调度任务…目录 基本概念 函数定义 函数实现与测试 测试1结果如下 测试2结果如下 基本概念 时间轮 是一种 实现延迟功能定时器 的 巧妙算法。如果一个系统存在大量的任务调度时间轮可以高效的利用线程资源来进行批量化调度。把大批量的调度任务全部都绑定时间轮上通过时间轮进行所有任务的管理触发以及运行。能够高效地管理各种延时任务周期任务通知任务等。 这几张图是了解了解用的可能看不懂用以解决mudo服务器中高并发性能的要求的 weak_ptr了解一下下 函数定义 #include iostream #include stdint.h #include functional #include vector #include memory #include unordered_mapusing TaskFunc std::functionvoid(); using ReleaseFunc std::functionvoid(); class TimerTask { private:uint64_t _id; // 定时器任务对象uint32_t _timeout; // 定时任务的超时时间TaskFunc _task_cb; // 定时器要执行的定时任务ReleaseFunc _release; // 用于删除TimerWheel中保存的定时器对象信息 public:TimerTask(uint64_t id, uint32_t delay, const TaskFunc cb) : _id(id), _timeout(delay), _task_cb(cb) {}~TimerTask(){_task_cb();_release();}void SetRelease(const ReleaseFunc cb) { _release cb; } };class TimerWheel { private:using WeakTask std::weak_ptrTimerTask;using PtrTask std::shared_ptrTimerTask;int _tick; // 当前的的秒针走到哪里哪里就释放执行int _capacity; // 表盘最大数量 -- 其实就是最大延迟时间std::vectorstd::vectorPtrTask _wheel;std::unordered_mapuint64_t, WeakTask _timers; // 用weak_ptr来构造出新的shared_ptr用来计数不过后续要记得释放 public:TimerWheel() : _capacity(60), _tick(0), _wheel(_capacity) {}void TimerAdd(uint64_t id, uint32_t delay, const TaskFunc cb); // 添加定时任务void TimerRefresh(uint64_t id); // 刷新/延迟定时任务 }; 函数实现与测试 #include iostream #include stdint.h #include functional #include vector #include memory #include unordered_map #include unistd.husing TaskFunc std::functionvoid(); using ReleaseFunc std::functionvoid(); class TimerTask { private:uint64_t _id; // 定时器任务对象uint32_t _timeout; // 定时任务的超时时间bool _canceled; // false-表示没有被取消true-表示被取消TaskFunc _task_cb; // 定时器要执行的定时任务ReleaseFunc _release; // 用于删除TimerWheel中保存的定时器对象信息 public:TimerTask(uint64_t id, uint32_t delay, const TaskFunc cb) : _id(id), _timeout(delay), _task_cb(cb), _canceled(false) {}~TimerTask(){if (_canceled false)_task_cb();_release();}void Cancel() { _canceled true; }void SetRelease(const ReleaseFunc cb) { _release cb; }uint32_t DelayTime() { return _timeout; } // 返回时间 };class TimerWheel { private:using WeakTask std::weak_ptrTimerTask;using PtrTask std::shared_ptrTimerTask;int _tick; // 当前的的秒针走到哪里哪里就释放执行int _capacity; // 表盘最大数量 -- 其实就是最大延迟时间std::vectorstd::vectorPtrTask _wheel;std::unordered_mapuint64_t, WeakTask _timers; // 用weak_ptr来构造出新的shared_ptr用来计数不过后续要记得释放 private:void RemoveTimer(uint64_t id){auto it _timers.find(id);if (it ! _timers.end()){_timers.erase(it);}}public:TimerWheel() : _capacity(60), _tick(0), _wheel(_capacity) {}void TimerAdd(uint64_t id, uint32_t delay, const TaskFunc cb) // 添加定时任务{PtrTask pt(new TimerTask(id, delay, cb)); // 实例化定时任务对象pt-SetRelease(std::bind(TimerWheel::RemoveTimer, this, id)); // 第0个位置是隐藏的this指针。再把任务id绑定进去int pos (_tick delay) % _capacity;_wheel[pos].push_back(pt);_timers[id] WeakTask(pt);}// 刷新/延迟定时任务void TimerRefresh(uint64_t id){// 通过保存的定时器对象的weak_ptr构造一个shared_ptr出来, 添加到轮子中auto it _timers.find(id);if (it _timers.end()){return; // 没找到定时任务, 没法刷新没法延迟}PtrTask pt it-second.lock(); // lock获取weak_ptr管理的对象对应的shared_ptrint delay pt-DelayTime(); // 获取到了初始的延迟时间int pos (_tick delay) % _capacity;_wheel[pos].push_back(pt);}void TimerCancel(uint64_t id){auto it _timers.find(id);if (it _timers.end()){return; // 没找到定时任务, 没法刷新没法延迟}PtrTask pt it-second.lock(); // 当还没有过期才进行取消if(pt) pt-Cancel();}// 这个函数应该每秒钟被执行一次相当于秒钟向后走了一步void RunTimerTask(){_tick (_tick 1) % _capacity;_wheel[_tick].clear(); // 清空指定位置的数组就会把数组中保存的所有管理定时器对象的shared_ptr释放掉.从而执行函数} };// 以下是测试 class Test { public:Test() { std::cout 构造 std::endl; }~Test() { std::cout 析构 std::endl; } };void DelTest(Test *t) {delete t; }int main() {TimerWheel tw;Test *t new Test();tw.TimerAdd(888, 5, std::bind(DelTest, t));for (int i 0; i 5; i){sleep(1);tw.TimerRefresh(888); // 刷新定时任务tw.RunTimerTask(); // 向后移动秒针std::cout 刷新了一下定时任务重新需要5s钟后才会销毁\n;}// tw.TimerCancel(888); // 取消定时任务的测试while (1){sleep(1);std::cout ------------------------\n;tw.RunTimerTask(); // 向后移动秒钟}return 0; } 测试1结果如下 达到预期 测试2结果如下 将下列代码放开 测试2结果如下 取消成功达到预期
http://www.pierceye.com/news/418575/

相关文章:

  • 建设邮箱网站桔子建站官网
  • 电子商务网站模板xampp下安装wordpress
  • 可以做动图的视频网站校园网站建设的目的
  • 专业网站制作公司塞尼铁克dw网页设计作品简单
  • 福州做网站公司有哪些中小企业网站制作塞尼铁克
  • 公司网站 钓鱼网站网站建设实训报告的内容怎么写
  • 摄影网站建设内容硬件开发语言有哪些
  • 怎么在主机上的建设网站做网站后台需要写代码吗
  • 网站建设发信息wordpress 科技类主题
  • 一站式进货平台网站建设为什么做网站编辑
  • 免费建站哪家好网站商城建设合同免费下载
  • 网站开发filter北京互联网
  • 德州市市政工程建设总公司网站设计公司的运营模式
  • 网站源码怎么弄境外注册网站
  • 肥城网站建设视频解析接口网站怎么做
  • 深圳做互联网教网站公司五百亿网站建设
  • 如何建自己网站周口网站建设费用
  • 延安网站建设哪家专业网站建设的大功效
  • 做网站交互demo工具服务器中安装wordpress
  • 2017年网站建设市场分析2345浏览器官网网址
  • 超大型网站建设怎么打广告吸引客户
  • 阳泉 网站建设合作国际网站设计
  • 东莞网站优化快速排名wordpress自适应设置宽度
  • wordpress的站点地址怎么设置青岛seo网站建设
  • wordpress 获取文章标签泰安企业网站seo
  • 网站可分为哪两种类型jsp网站建设项目实战 pdf
  • 科技类网站简介怎么做网站建设公司的工资
  • 东莞网站推广怎么做网站备案和备案的区别
  • 免费的舆情网站app开放平台设计方案
  • 昆明驿站网站建设程序做网站好还是app好