cp_thread_pool

Section: cp_thread_pool (3)
Updated: OCTOBER 2005
Index Return to Main Contents
 

NAME

cp_pooled_thread_scheduler - a load balancing component for pooled threads  

SYNOPSIS

#include <cprops/thread.h>

cp_pooled_thread_scheduler *
      cp_pooled_thread_scheduler_create(cp_thread_pool *pool);

void cp_pooled_thread_scheduler_destroy(
           cp_pooled_thread_scheduler *scheduler);

void cp_pooled_thread_scheduler_register_client(
           cp_pooled_thread_scheduler *scheduler,
           cp_pooled_thread_client_interface* client );

 

DESCRIPTION


The pooled cp_thread scheduler interface is meant for use by clients who require a variable number of threads. Each such component should create an instance of cp_pooled_thread_client_interface and use the api functions to get threads from the underlying cp_thread_pool. To use the scheduler,


 o create a thread pool 

 o instantiate the scheduler with the thread pool

 o create cp_pooled_thread_client_interfaces instances describing the 
    actions to be load balanced

 o register the client interface instances with the scheduler.

cp_pooled_thread_scheduler_create creates a scheduler instance for the specified pool. cp_pooled_thread_scheduler_destroy performs cleanup of scheduler instances. cp_pooled_thread_scheduler_register_client registers a client with the scheduler.  

EXAMPLE


cp_pooled_thread_scheduler *main_scheduler; 
component_a_start(component_a *a, ...)
{
    a->scheduler_interface = 
        cp_pooled_thread_client_interface_create(main_scheduler, a, 
            2, 10, component_a_report_load, component_a_stop_thread, 
            component_a_thread_run, a);





     ...





    for (i = 0; i < a->scheduler_interface->min; i++)
        cp_pooled_thread_client_get(a->scheduler_interface);
}





component_b_start(component_b *b, ...)
{
    b->scheduler_interface = 
        cp_pooled_thread_client_interface_create(main_scheduler, b, 
            2, 10, component_a_report_load, component_a_stop_thread, 
            component_a_thread_run, b);





     ...





    for (i = 0; i < b->scheduler_interface->min; i++)
        cp_pooled_thread_client_get(b->scheduler_interface);
}





 



In this example, the cp_threads for component_a and component_b will be managed jointly, since their cp_pooled_thread_client_interface *'s have the same cp_pooled_thread_scheduler *.
 

SEE ALSO

cp_thread_pool(3), cp_pooled_thread_client_interface(3)


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLE
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 17:35:34 GMT, December 30, 2005
SourceForge
.net Logo