thread_pool_executor


The os_thread_pool_executor class implements the thread pool execution concurrency strategy. It uses the os_thread_pool class for its implementation. The execute() member function enqueues the handler for execution by a thread pool. The void* run() method of the handler is executed by the next available idle thread in the pool. Refer to os_thread_pool class for more information on thread pools. This class can be used to execute handlers in the os_tcp_acceptor and os_tcp_connector classes.

Use of member template feature in the execute method gives the flexibility of not having the handler classes to inherit from a specific runnable interface class. Therefore, the compiler must be able to support member templates and OS_ENABLE_MEMBER_TEMPLATE_FEATURES must be defined to use this class.

Library

Framework<ToolKit>

Declaration

#include <ospace/framework/executor.h>

class os_thread_pool_executor : public os_thread_pool

Interface

Constructor
os_thread_pool_executor( size_t max_pool_size , size_t max_idle_threads , long keep_alive_time )
Constructs a thread pool object with the specified limits. The maximum number of threads the pool can create is set to max_pool_size (default 100 ). The maximum number of idle threads the pool can cache is set to max_idle_threads (default 10 ). Any threads that become idle after the max_idle_threads limit is reached are kept for keep_alive_time milliseconds before they are discarded. If keep_alive_time is 0 (default), then any extra threads that become idle after the max_idle_threads limit is reached are discarded immediately.
execute
template< class ServiceHandler >
void execute( ServiceHandler* handler )
Enqueues the handler for execution by the next available thread for the thread pool. The calling thread returns immediately. The void* run() method of handler will be called by the next free thread.

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.