load_balancer
#include <gempba/core/load_balancer.hpp> // included automatically via gempba.hpp
Abstract interface for thread-level work distribution within a single process. node_manager holds a pointer to one and routes all submission calls through it.
Built-in implementations: Quasi-Horizontal (recommended), Work-Stealing (baseline).
Member types
enum balancing_policy { /* implementation-defined values */ };
get_balancing_policy().
Member functions
Configuration
virtual void set_thread_pool_size(unsigned int size) = 0;
Task submission
virtual bool try_local_submit(node& p_node) = 0;
p_node to an idle thread. Returns false if pool is full — the caller must run the node inline.
virtual void forward(node& p_node) = 0;
p_node on the calling thread immediately.
virtual bool try_remote_submit(node& p_node, int runnable_id) = 0;
p_node to another process via the wired-in scheduler. runnable_id selects the matching serial_runnable on the remote side. Only meaningful in multiprocessing mode.
virtual std::future<std::any> force_local_submit(std::function<std::any()>&&) = 0;
Monitoring
[[nodiscard]] virtual double get_idle_time() const = 0;
[[nodiscard]] virtual bool is_done() const = 0;
[[nodiscard]] virtual std::size_t get_thread_request_count() const = 0;
get_idle_time() — cumulative wall-clock milliseconds threads spent waiting for work.
is_done() — true when queue is empty and all threads are idle.
get_thread_request_count() — total tasks submitted since startup.
Synchronization
virtual void wait() = 0;
Per-thread root management
virtual std::shared_ptr<std::shared_ptr<node_core>>
get_root(std::thread::id thread_id) = 0;
virtual void set_root(std::thread::id thread_id,
std::shared_ptr<node_core>& root) = 0;
Identification
virtual balancing_policy get_balancing_policy() = 0;
virtual unsigned int generate_unique_id() = 0;
Custom implementation
class MyLoadBalancer : public gempba::load_balancer {
// implement all pure virtuals above
};
auto* lb = gempba::mt::create_load_balancer(std::make_unique<MyLoadBalancer>());
Study quasi_horizontal_load_balancer in private/impl/load_balancing/ for the expected semantics of every tree navigation call before writing from scratch.