I am trying to understand the source code of boost.thread.executor.serial_executor.

In the serial_executor.hpp, line 112, we can see there are two while loops in the worker_thread function:

/**
* The main loop of the worker thread
*/
void worker_thread()
{
   while (!closed())
   {
        schedule_one_or_yield();
   }
   while (try_executing_one())
   {
   }
}

Seems if the first loop finished, the work_queue should closed, then try_executing_one won't return true again, so the second loop would not do anything, is it?

So, what's the purpose of the second while loop?

Thanks.

0 Answers