c++ – Number of threads for domain name resolution in boost asio

  1. According to the boost::asio documentation, for each io_context one or more additional threads can be created that will be used for host resolution.

One or more additional threads per io_context to emulate asynchronous
host resolution. By default, only one thread is created, but this
behaviour may be altered via the “resolver” / “threads” configuration
option.

www.boost.org/doc/libs/latest/doc/html/boost_asio/overview/implementation.html

This link contains instructions on how to set the number of threads that will be used in the case of asynchronous host resolution
www.boost.org/doc/libs/latest/doc/html/boost_asio/overview/core/configuration.html

Following these instructions, I used the following code to set the number of resolver threads to 16.

#include 
#include 
#include 
#include 

using boost::asio::ip::tcp;

int main() {
    boost::asio::io_context io(boost::asio::config_from_string("resolver.threads=16\n"));

    tcp::resolver resolver(io);

    resolver.async_resolve(
        "example.com",
        "443",
        [&](const boost::system::error_code& ec, tcp::resolver::results_type results)
        {
            if (ec) {
                std::cout << "Resolve failed: " << ec.message() << "\n";
                return;
            }

            std::cout << "Resolve OK:\n";
            for (const auto& entry : results) {
                std::cout << "  " << entry.endpoint() << "\n";
            }

            std::this_thread::sleep_for(std::chrono::minutes(1));
        }
    );

    io.run();
    return 0;
}

Then I use tools to track the number of threads in the process and I see that there are less than 16 threads, although logically there should be at least 17 threads in this process.

My question is, why doesn’t the number of resolver threads change despite the settings I’ve specified? Am I doing something wrong?

Testing was conducted on Windows 11.

Read more here: Source link