What's New in Asio - Properties

What's New in Asio - Properties

Article 1 of n

The forthcoming release of Asio, which will ship as part of Boost 1.74, includes a great number of new features and improvements. In this series of articles we will preview some of these changes.

The biggest change is a (partial) implementation of the proposed standard C++ executor model, and a reworking of Asio's asynchronous operations in terms of it. One of the driving requirements of this unified standard executor design is extensibility, particularly when it comes to domain-specific and vendor-specific needs. This extensibility is enabled by another proposed c++ library feature: properties.

The following video was originally created for the standards committee, and gives an introduction to the properties mechanism and its use:


Here is an example of properties being used with executors:

asio::static_thread_pool pool(1);
auto ex1 = ctx.get_executor();

// Get the number of available threads in the pool.
std::size_t n = asio::query(ex1, asio::execution::occupancy);

// Require an executor with blocking.never property.
auto ex2 = asio::require(ex1, asio::execution::blocking.never);
asio::execution::execute(ex2, []{ /*...*/ });

// Prefer an executor that uses a custom allocator.
auto ex3 = asio::prefer(ex2, asio::execution::allocator(my_allocator));
asio::execution::execute(ex3, []{ /*...*/ });

Obviously the properties implementation in Asio is under the asio namespace, rather than std, so we must use asio::require(...) rather than std::require(...), and so on.

For now, Asio uses properties only for executors, as shown above. In the future, the facility will be used for other entities too, such as buffers and completion handlers, to add extensibility and create new opportunities for optimisation.