我们再来看看task_io_service的实现
task_io_service提供的最主要的接口如下:
1) run:Run the event loop until interrupted or no more work.
size_t run(boost::system::error_code& ec)
{
ec = boost::system::error_code();
//如果没有任务了,直接退出
if (outstanding_work_ == 0)
{
stop();
return 0;
}
typename call_stack<task_io_service>::context ctx(this);
idle_thread_info this_idle_thread;
this_idle_thread.next = 0;
boost::asio::detail::mutex::scoped_lock lock(mutex_);
//循环执行直到完成所有任务队列中的任务
size_t n = 0;
for (; do_one(lock, &this_idle_thread); lock.lock())
if (n != (std::numeric_limits<size_t>::max)())
++n;
return n;
}