We have a server implemented with boost::asio that uses a vector of threads with a single io_service as in the asio http server 3 sample program.

 

We want to check on the liveness of threads by having each thread periodically call back to a thread manager so that we can confirm it is still running.

 

To do that we have an inner loop that uses run_one() so we can call our heartbeat function after each action is completed (pseudo code):

 

    do

  {

      num_ops = io_svc.run_one(ec)

      heartbeat_to_thread_manager();

  }

  while (num_ops > 0);

 

However, asio makes no garantees on how work is dispatched to threads.  In our testing work seems to go  prefentially to one thread for several iterations before going to another thread with no pattern that we can find.

 

Is there some way we can change this solution so that we can be reasonably sure each thread will be called at least once in a some period of time or some other mechanism for monitoring thread liveness?

 

Thanks,

 

Mike