NAME

ACE_TP_Reactor - Specialization of Select Reactor to support thread-pool based event dispatching.

SYNOPSIS

#include <ace/TP_Reactor.h>

class ACE_TP_Reactor : public ACE_Select_Reactor { public: ACE_TP_Reactor ( ACE_Sig_Handler * = 0, ACE_Timer_Queue * = 0, int mask_signals = 1 ); ACE_TP_Reactor ( size_t max_number_of_handles, int restart = 0, ACE_Sig_Handler * = 0, ACE_Timer_Queue * = 0, int mask_signals = 1 ); virtual int handle_events (ACE_Time_Value *max_wait_time = 0); virtual int handle_events (ACE_Time_Value &max_wait_time); virtual int mask_ops ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask, int ops ); virtual int mask_ops ( ACE_HANDLE handle, ACE_Reactor_Mask mask, int ops ); static void no_op_sleep_hook (void *); virtual void wakeup_all_threads (void); ACE_ALLOC_HOOK_DECLARE; protected: virtual int dispatch_io_set ( int number_of_active_handles, int& number_dispatched, int mask, ACE_Handle_Set& dispatch_mask, ACE_Handle_Set& ready_mask, ACE_EH_PTMF callback ); virtual void notify_handle ( ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Handle_Set &, ACE_Event_Handler *eh, ACE_EH_PTMF callback ); virtual int notify_handle (ACE_EH_Dispatch_Info &dispatch_info); ACE_EH_Dispatch_Info dispatch_info_; private: ACE_TP_Reactor (const ACE_TP_Reactor &); ACE_TP_Reactor &operator = (const ACE_TP_Reactor &); };

DESCRIPTION

The ACE_TP_Reactor (aka, Thread Pool Reactor) uses the Leader/Followers pattern to demultiplex events among a pool of threads. When using a thread pool reactor, an application pre-spawns a _fixed_ number of threads. When these threads invoke the ACE_TP_Reactor's handle_events method, one thread will become the leader and wait for an event. The other follower threads will queue up waiting for their turn to become the leader. When an event occurs, the leader will pick a follower to become the leader and go on to handle the event. The consequence of using ACE_TP_Reactor is the amortization of the costs used to creating threads. The context switching cost will also reduce. More over, the total resources used by threads are bounded because there are a fixed number of threads.

Initialization and termination methods.

ACE_TP_Reactor (
    ACE_Sig_Handler * = 0,
    ACE_Timer_Queue * = 0,
    int mask_signals = 1
    );

ACE_TP_Reactor (
    size_t max_number_of_handles,
    int restart = 0,
    ACE_Sig_Handler * = 0,
    ACE_Timer_Queue * = 0,
    int mask_signals = 1
    );

Event loop drivers.

virtual int handle_events (ACE_Time_Value *max_wait_time = 0);

virtual int handle_events (ACE_Time_Value &max_wait_time);

virtual int mask_ops (
    ACE_Event_Handler *eh,
    ACE_Reactor_Mask mask,
    int ops
    );

virtual int mask_ops (
    ACE_HANDLE handle,
    ACE_Reactor_Mask mask,
    int ops
    );

static void no_op_sleep_hook (void *);

virtual void wakeup_all_threads (void);

ACE_ALLOC_HOOK_DECLARE;

Internal methods that do the actual work.

virtual int dispatch_io_set (
    int number_of_active_handles,
    int& number_dispatched,
    int mask,
    ACE_Handle_Set& dispatch_mask,
    ACE_Handle_Set& ready_mask,
    ACE_EH_PTMF callback
    );

virtual void notify_handle (
    ACE_HANDLE handle,
    ACE_Reactor_Mask mask,
    ACE_Handle_Set &,
    ACE_Event_Handler *eh,
    ACE_EH_PTMF callback
    );

virtual int notify_handle (ACE_EH_Dispatch_Info &dispatch_info);

ACE_EH_Dispatch_Info dispatch_info_;

AUTHOR

Irfan Pyarali irfan@cs.wustl.edu and Nanbor Wang nanbor@cs.wustl.edu

LIBRARY

ace