Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 1.27 KB

cpp-asio.rst

File metadata and controls

28 lines (24 loc) · 1.27 KB

Asynchronous I/O

The C++ API uses Boost.Asio for asynchronous operations. There is a :cppspead2::thread_pool class (essentially the same as the Python :pyspead2.ThreadPool class). However, it is not required to use this, and you may for example run everything in one thread to avoid multi-threading issues.

spead2::thread_pool

Classes that perform asynchronous operations take a parameter of type :cppspead2::io_service_ref. This can be (implicitly) initialised from either a :cppboost::asio::io_service reference, a :cppspead2::thread_pool reference, or a :cppstd::shared_ptr\<spead2::thread_pool\>. In the last case, the receiving class retains a copy of the shared pointer, providing convenient lifetime management of a thread pool.

spead2::io_service_ref

A number of the APIs use callbacks. These follow the usual Boost.Asio guarantee that they will always be called from threads running :cppboost::asio::io_service::run. If using a :cpp~spead2::thread_pool, this will be one of the threads managed by the pool. Additionally, callbacks for a specific stream are serialised, but there may be concurrent callbacks associated with different streams.