修复EventLoopThread的析构和EventLoop的loop之间存在的时序问题 #442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在运行muduo/muduo/net/tests/EventLoopThreadPool_unittest.cc时发现EventLoopThreadPool::start对于3个EventLoopThread的情况存在一些时序上的问题,我列在了这里https://github.com/chenshuo/muduo/issues/441。
其原因我认为是EventLoopThreadPoll::startLoop里面的EventLoopThread::threadFunc还没执行到EventLoop::loop,就发生了EventLoopThreadPoll的析构,此时EventLoop::quit发生在EventLoop::loop之前,本应该退出的线程的EventLoop::quit_标志位被EventLoop::loop清除(此处你也标注了FIXME),我认为EventLoopThread::threadFunc中启动EventLoop完成的标志应该是EventLoop::loop开始运行,而不是loop_ = &loop; 因此,将cond_.notify();调整到了EventLoop正式开始后才确认EventLoopThread::startLoop操作正式完成,以此修正这个时序问题。