Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::integration::basic_thread_pool Class Reference

Basic thread pool implementation for standalone use. More...

#include <thread_integration.h>

Inheritance diagram for kcenon::network::integration::basic_thread_pool:
Inheritance graph
Collaboration diagram for kcenon::network::integration::basic_thread_pool:
Collaboration graph

Classes

class  impl
 

Public Member Functions

 basic_thread_pool (size_t num_threads=0)
 Construct with specified number of threads.
 
 ~basic_thread_pool ()
 
std::future< void > submit (std::function< void()> task) override
 Submit a task to the thread pool.
 
std::future< void > submit_delayed (std::function< void()> task, std::chrono::milliseconds delay) override
 Submit a task with delay.
 
size_t worker_count () const override
 Get the number of worker threads.
 
bool is_running () const override
 Check if the thread pool is running.
 
size_t pending_tasks () const override
 Get pending task count.
 
void stop (bool wait_for_tasks=true)
 Stop the thread pool.
 
size_t completed_tasks () const
 Get completed tasks count.
 
- Public Member Functions inherited from kcenon::network::integration::thread_pool_interface
virtual ~thread_pool_interface ()=default
 
virtual ~thread_pool_interface ()=default
 

Private Attributes

std::shared_ptr< implpimpl_
 PIMPL pointer with intentional leak pattern.
 

Detailed Description

Basic thread pool implementation for standalone use.

This provides a simple thread pool implementation for when thread_system is not available.

Definition at line 81 of file thread_integration.h.

Constructor & Destructor Documentation

◆ basic_thread_pool()

kcenon::network::integration::basic_thread_pool::basic_thread_pool ( size_t num_threads = 0)
explicit

Construct with specified number of threads.

Parameters
num_threadsNumber of worker threads (0 = hardware concurrency)

Definition at line 406 of file thread_integration.cpp.

411 : pimpl_(new impl(num_threads), [](impl*) { /* no-op deleter - intentional leak */ }) {
412}
std::shared_ptr< impl > pimpl_
PIMPL pointer with intentional leak pattern.

◆ ~basic_thread_pool()

kcenon::network::integration::basic_thread_pool::~basic_thread_pool ( )
default

Member Function Documentation

◆ completed_tasks()

size_t kcenon::network::integration::basic_thread_pool::completed_tasks ( ) const

Get completed tasks count.

Returns
Number of completed tasks

Definition at line 443 of file thread_integration.cpp.

443 {
444 return pimpl_->get_completed_tasks();
445}

References pimpl_.

◆ is_running()

bool kcenon::network::integration::basic_thread_pool::is_running ( ) const
overridevirtual

Check if the thread pool is running.

Returns
true if running, false otherwise

Implements kcenon::network::integration::thread_pool_interface.

Definition at line 431 of file thread_integration.cpp.

431 {
432 return pimpl_->is_running();
433}

References pimpl_.

◆ pending_tasks()

size_t kcenon::network::integration::basic_thread_pool::pending_tasks ( ) const
overridevirtual

Get pending task count.

Returns
Number of tasks waiting to be executed

Implements kcenon::network::integration::thread_pool_interface.

Definition at line 435 of file thread_integration.cpp.

435 {
436 return pimpl_->pending_tasks();
437}

References pimpl_.

◆ stop()

void kcenon::network::integration::basic_thread_pool::stop ( bool wait_for_tasks = true)

Stop the thread pool.

Parameters
wait_for_tasksWhether to wait for pending tasks

Definition at line 439 of file thread_integration.cpp.

439 {
440 pimpl_->stop(wait_for_tasks);
441}

References pimpl_.

◆ submit()

std::future< void > kcenon::network::integration::basic_thread_pool::submit ( std::function< void()> task)
overridevirtual

Submit a task to the thread pool.

Parameters
taskThe task to execute
Returns
Future for the task result

Implements kcenon::network::integration::thread_pool_interface.

Definition at line 416 of file thread_integration.cpp.

416 {
417 return pimpl_->submit(task);
418}

References pimpl_.

◆ submit_delayed()

std::future< void > kcenon::network::integration::basic_thread_pool::submit_delayed ( std::function< void()> task,
std::chrono::milliseconds delay )
overridevirtual

Submit a task with delay.

Parameters
taskThe task to execute
delayDelay before execution
Returns
Future for the task result

Implements kcenon::network::integration::thread_pool_interface.

Definition at line 420 of file thread_integration.cpp.

423 {
424 return pimpl_->submit_delayed(task, delay);
425}

References pimpl_.

◆ worker_count()

size_t kcenon::network::integration::basic_thread_pool::worker_count ( ) const
overridevirtual

Get the number of worker threads.

Returns
Number of worker threads

Implements kcenon::network::integration::thread_pool_interface.

Definition at line 427 of file thread_integration.cpp.

427 {
428 return pimpl_->worker_count();
429}

References pimpl_.

Member Data Documentation

◆ pimpl_

std::shared_ptr<impl> kcenon::network::integration::basic_thread_pool::pimpl_
private

PIMPL pointer with intentional leak pattern.

Uses shared_ptr with no-op deleter to prevent heap corruption during static destruction. This is intentional - see docs/DESIGN_DECISIONS.md for detailed rationale.

Note
Memory is intentionally not freed. This is safe because:
  • Only ~100-200 bytes per instance
  • Process terminates immediately after static destruction
  • OS reclaims all process memory on exit
Warning
Do not "fix" this by changing to unique_ptr or adding a real deleter. Doing so will cause heap corruption on shutdown.
See also
docs/DESIGN_DECISIONS.md#intentional-leak-pattern

Definition at line 133 of file thread_integration.h.

Referenced by completed_tasks(), is_running(), pending_tasks(), stop(), submit(), submit_delayed(), and worker_count().


The documentation for this class was generated from the following files: