chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.7k stars 5.15k forks source link

Why clear `cancelingTimers_` before using it? #537

Closed ehds closed 2 years ago

ehds commented 2 years ago

Linux distro and version? x86 or ARM? 32-bit or 64-bit?

Ubuntu 21.04 x86_64

Branch (cpp98/cpp11/cpp17) and version of muduo?

cpp11 muduo version: 90920bbad80e544da9a8a94b16ad8ab4bb66e652

Version of cmake, gcc and boost? (If not from distro.)

cmake version 3.22.1 gcc version 10.3.0

In TimerQueue::handleRead, cancelingTimers_ will be cleared before reset. https://github.com/chenshuo/muduo/blob/90920bbad80e544da9a8a94b16ad8ab4bb66e652/muduo/net/TimerQueue.cc#L172 Then reset will use cancelingTimers_ again to find canceled timers. https://github.com/chenshuo/muduo/blob/90920bbad80e544da9a8a94b16ad8ab4bb66e652/muduo/net/TimerQueue.cc#L212 But TimerQueue::handleRead always happened before TimerQueue::reset and in the same loop thread. It seems that cancelingTimers_ is useless. I have no idea what's the purpose of cancelingTimers_.

ehds commented 2 years ago

Timer callback maybe cancel timer.