Asynchronous I/O

The C++ API uses Boost.Asio for asynchronous operations. There is a spead2::thread_pool class (essentially the same as the Python spead2.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.

class spead2::thread_pool

Combination of a boost::asio::io_service with a set of threads to handle the callbacks.

The threads are created by the constructor and shut down and joined in the destructor.

Subclassed by spead2::thread_pool_wrapper

Public Functions

thread_pool(int num_threads, const std::vector<int> &affinity)

Construct with explicit core affinity for the threads.

The affinity list can be shorter or longer than num_threads. Threads are allocated in round-robin fashion to cores. Failures to set affinity are logged but do not cause an exception.

boost::asio::io_service &get_io_service()

Retrieve the embedded io_service.

void stop()

Shut down the thread pool.

Public Static Functions

void set_affinity(int core)

Set CPU affinity of current thread.

A number of the APIs use callbacks. These follow the usual Boost.Asio guarantee that they will always be called from threads running boost::asio::io_service::run(). If using a 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.