I’d like to extend my work queue that is based on io_context, so it’ll perform also sync/async tasks that doesn’t involve network communication … So here’s how I define the consumer threads
// class members
boost::thread_group workers_;
boost::asio::io_context ioc_;
// the main run method
for (size_t i = 1; i < kThreads; ++i) {
workers_.create_thread([this]() {
ioc_.run();
});
}
ioc_.run();
workers_.join_all();
and here are some usage examples for serial commands
boost::asio::strand<boost::asio::io_context::executor_type> strand_;
....
strand_(boost::asio::make_strand(ioc_))
....
boost::asio::post(strand_, [=]() { auto resp = doSomeStuffInForeground());
and parallel
boost::asio::spawn(ioc_, [=](const boost::asio::yield_context &yield) {
doSomeStuffInBackground(yield);
});
And now my program have more tasks rather than network communication, and I’d like to recycles those iocontext related threads to operate them as well (i.e. to put non communication related code inside doSomeStuffBackground and/or doSomeStuffForeground). I wonder if it’s a good approach…
Also, I wonder if I can define some priority tasks that have precedence on other tasks And last, I wonder if I can aggregate/merge several tasks from the queue that are similar. Thanks for the help !