Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

make_dispatcher

Instatiates the best available async_file_io_dispatcher implementation for this system for the given uri.

Description

Note that the number of threads in the threadpool supplied is the maximum non-async op queue depth (e.g. file opens, closes etc.). For fast SSDs, there isn't much gain after eight-sixteen threads, so the process threadpool is set to eight by default. For slow hard drives, or worse, SANs, a queue depth of 64 or higher might deliver significant benefits.

URIs currently supported by AFIO:

Synopsis
BOOST_AFIO_DECL outcome<dispatcher_ptr> make_dispatcher(std::string uri = "file : / / /", file_flags flagsforce = file_flags::none, file_flags flagsmask = file_flags::none,
                                                          std::shared_ptr< thread_source > threadpool = process_threadpool())
Parameters

Type

Concept

Name

Description

std::string

uri

Where to open the dispatcher upon.

file_flags

flagsforce

The flags to bitwise OR with any opened file flags. Used to force on certain flags.

file_flags

flagsmask

The flags to bitwise AND with any opened file flags. Used to force off certain flags.

std::shared_ptr< thread_source >

threadpool

The threadpool instance to use for asynchronous dispatch.

Returns

A shared_ptr to the best available async_file_io_dispatcher implementation for this system for the given uri.

Header

#include <boost/afio/v2/afio.hpp>

Example
// Create a dispatcher instance
auto dispatcher = boost::afio::make_dispatcher().get();

// Schedule an asynchronous call of some function with some bound set of arguments
auto helloworld = dispatcher->call(boost::afio::future<>() /* no precondition */,
                                   [](std::string text) -> int
                                   {
                                     std::cout << text << std::endl;
                                     return 42;
                                   },
                                   std::string("Hello world"));

// Schedule as asynchronous call of some function to occur only after helloworld
// completes
auto addtovalue = dispatcher->call(helloworld, [&helloworld]() -> int
                                               {
                                                 return helloworld.get() + 1;
                                               });

// Print the result returned by the future for the lambda, which will be 43
std::cout << "addtovalue() returned " << addtovalue.get() << std::endl;


PrevUpHomeNext