定时器  时序图

muduo库 TimerQueue 分析

对于定时任务的原理:

  1. muduo采用timerfd_*将超时任务转换成文件描述符进行监听
  2. 当时间一到,timerfd变为可读,相应的Channel调用回调函数(TimerQueue::handleRead
  3. 回调函数中将所有在TimerQueue中的超时任务找出,一次调用其回调函数
  4. 对于周期性定时任务,再添加回TimerQueue








相关文章: