Class ThreadManager

Nested Relationships

Nested Types

Class Documentation

class ThreadManager

DPDK Thread manager class for a thread-per-core model.

DPDK deploys worker threads when launched, this class can be used to run threads on these DPDK worker threads. This class can only be used on the main lcore of the program.

This class is designed to be used in a thread-per-core topology, every thread that is spawned with this class is guaranteed to run on a different physical processor.

The class tries to mimic the std::jthread API for launching threads, the completion of threads is awaited when the destructor is called.

Public Types

enum class LaunchThreadResult

Values:

enumerator Success
enumerator MaxLCoreReached
enumerator NotMainLCore
enumerator RemoteLaunchFail

Public Functions

inline ThreadManager()

Construct a new Thread Manager object.

inline ~ThreadManager()

Destroy the Thread Manager object.

Requests stopping all threads and waits for the threads to exit

inline void join()

Wait until the LCores have exited.

ThreadManager(const ThreadManager&) = delete

The thread manager cannot be copied.

ThreadManager(const ThreadManager&&) = delete

The thread manager cannot be moved.

template<typename F, typename ...Ts>
LaunchThreadResult LaunchThread(F &&f, Ts&&... args)

Launch a new thread on a new lcore.

Throws a runtime error when no lcore is available for the thread

Template Parameters:
  • F – Template for lambda to be called

  • Ts – Parameter pack template for arguments for F

Parameters:
  • fCaptureless lambda to be ran on the new thread

  • args – Parameters to apply to f in the new thread

inline unsigned GetTotalThreads() const

Get the total number of usable hardware threads available on the system.

Returns:

unsigned Total number of usable hardware threads available on the system

inline unsigned GetUnusedThreads() const

Get the number of unused hardware threads.

Returns:

unsigned Number of unused hardware threads

inline std::stop_source get_stop_source()

Get the stop source object.

Returns:

stop_source

inline std::stop_token get_stop_token() const

Get a new stop_token from _stop_source.

Returns:

std::stop_token

inline bool request_stop() noexcept

Request the threads to stop through the _stop_source object.

Returns:

true if the ThreadManager object has a stop-state and this invocation made a stop request

Returns:

false otherwise