NAME
ACE_Thread_Manager -
Manages a pool of threads.
SYNOPSIS
#include <ace/Thread_Manager.h >
class ACE_Thread_Manager
{
public:
enum{ DEFAULT_SIZE = 100 };
inline ACE_Thread_Manager (int = 0);
inline ~ACE_Thread_Manager (void);
inline int open (size_t = DEFAULT_SIZE);
inline int close (void);
inline int spawn (
ACE_THR_FUNC,
void * = 0,
long = 0,
ACE_thread_t * = 0,
ACE_hthread_t * = 0,
u_int = 0,
int = -1,
void * = 0,
size_t = 0
);
friend class ACE_Thread_Control;
enum{ DEFAULT_SIZE = 100 };
ACE_Thread_Manager (
size_t size = ACE_Thread_Manager::DEFAULT_SIZE
);
~ACE_Thread_Manager (void);
int open (size_t size = DEFAULT_SIZE);
int close (void);
int spawn (
ACE_THR_FUNC func,
void *args = 0,
long flags = THR_NEW_LWP,
ACE_thread_t * = 0,
ACE_hthread_t *t_handle = 0,
u_int priority = 0,
int grp_id = -1,
void *stack = 0,
size_t stack_size = 0
);
int spawn_n (
int n,
ACE_THR_FUNC func,
void *args = 0,
long flags = THR_NEW_LWP,
u_int priority = 0,
int grp_id = -1
);
void *exit (void *status, int do_thread_exit = 1);
int wait (const ACE_Time_Value *timeout = 0);
int thread_descriptor (ACE_thread_t, ACE_Thread_Descriptor &);
int hthread_descriptor (ACE_hthread_t, ACE_Thread_Descriptor &);
int thr_self (ACE_hthread_t &);
int suspend_all (void);
int suspend (ACE_thread_t);
int suspend_grp (int grp_id);
int testsuspend (ACE_thread_t t_id);
int resume_all (void);
int resume (ACE_thread_t);
int resume_grp (int grp_id);
int testresume (ACE_thread_t t_id);
int kill_all (int signum);
int kill (ACE_thread_t, int signum);
int kill_grp (int grp_id, int signum);
int cancel_all (void);
int cancel (ACE_thread_t);
int cancel_grp (int grp_id);
int testcancel (ACE_thread_t t_id);
int set_grp (ACE_thread_t, int grp_id);
int get_grp (ACE_thread_t, int &grp_id);
void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
private:
int resize (size_t);
int spawn_i (
ACE_THR_FUNC func,
void *args,
long flags,
ACE_thread_t * = 0,
ACE_hthread_t *t_handle = 0,
u_int priority = 0,
int grp_id = -1,
void *stack = 0,
size_t stack_size = 0
);
int find (ACE_thread_t t_id);
int insert_thr (
ACE_thread_t t_id,
ACE_hthread_t,
int grp_id = -1
);
int append_thr (
ACE_thread_t t_id,
ACE_hthread_t,
ACE_Thread_State,
int grp_id
);
void remove_thr (int i);
int thread_descriptor_i (ACE_thread_t, ACE_Thread_Descriptor &);
int hthread_descriptor_i (ACE_hthread_t, ACE_Thread_Descriptor &);
typedef int (ACE_Thread_Manager::*THR_FUNC)(int, int);
int check_state (ACE_Thread_State state, ACE_thread_t thread);
int apply_grp (int grp_id, THR_FUNC, int = 0);
int apply_all (THR_FUNC, int = 0);
int resume_thr (int i);
int suspend_thr (int i);
int kill_thr (int i, int signum);
int cancel_thr (int i);
ACE_Thread_Descriptor *thr_table_;
size_t max_table_size_;
size_t current_count_;
int grp_id_;
ACE_Thread_Mutex lock_;
ACE_Condition_Thread_Mutex zero_cond_;
};
DESCRIPTION
This class allows operations on groups of threads atomically.
Initialization and termination methods.
ACE_Thread_Manager (size_t size = ACE_Thread_Manager::DEFAULT_SIZE);
~ACE_Thread_Manager (void);
int open (size_t size = DEFAULT_SIZE);
Initialize the manager with room for SIZE threads.
int close (void);
int spawn (
ACE_THR_FUNC func,
void *args = 0,
long flags = THR_NEW_LWP,
ACE_thread_t * = 0,
ACE_hthread_t *t_handle = 0,
u_int priority = 0,
int grp_id = -1,
void *stack = 0,
size_t stack_size = 0
);
Create a new thread, which executes func.
Returns: on success a unique group id that can be used to control
other threads added to the same group. On failure, returns -1.
int spawn_n (
int n,
ACE_THR_FUNC func,
void *args = 0,
long flags = THR_NEW_LWP,
u_int priority = 0,
int grp_id = -1
);
Create N new threads, all of which execute func.
Returns: on success a unique group id that can be used to control
all of the threads in the same group. On failure, returns -1.
void *exit (void *status, int do_thread_exit = 1);
Called to clean up when a thread exits. If do_thread_exit is
non-0 then ACE_Thread::exit is called to exit the thread, in
which case status is passed as the exit value of the thread.
int wait (const ACE_Time_Value *timeout = 0);
Block until there are no more threads running or timeout
expires. Returns 0 on success and -1 on failure.
= Accessors for ACE_Thread_Descriptors.
int thread_descriptor (ACE_thread_t, ACE_Thread_Descriptor &);
Return the thread descriptor (indexed by ACE_thread_t). Returns 0 on
success and -1 if not found.
int hthread_descriptor (ACE_hthread_t, ACE_Thread_Descriptor &);
Return the thread descriptor (indexed by ACE_hthread_t). Returns 0
on success and -1 if not found.
int thr_self (ACE_hthread_t &);
Passes out the "real" handle to the thread, caching it if
necessary in TSS to speed up subsequent lookups.
Suspend methods.
int suspend_all (void);
int suspend (ACE_thread_t);
int suspend_grp (int grp_id);
Suspend a group of threads.
int testsuspend (ACE_thread_t t_id);
True if t_id is inactive (i.e., suspended), else false.
Resume methods.
int resume_all (void);
Resume all stopped threads
int resume (ACE_thread_t);
int resume_grp (int grp_id);
Resume a group of threads.
int testresume (ACE_thread_t t_id);
True if t_id is active (i.e., resumed), else false.
Kill methods (send signals...).
int kill_all (int signum);
Send signum to all stopped threads
int kill (ACE_thread_t, int signum);
int kill_grp (int grp_id, int signum);
Cancel methods (send signals...).
int cancel_all (void);
Send signum to all stopped threads
int cancel (ACE_thread_t);
int cancel_grp (int grp_id);
Cancel a group of threads.
int testcancel (ACE_thread_t t_id);
True if t_id is cancelled, else false.
Set/get group ids for a particular thread id.
int set_grp (ACE_thread_t, int grp_id);
int get_grp (ACE_thread_t, int &grp_id);
void dump (void) const;
Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
Declare the dynamic allocation hooks.
The following four methods implement a simple scheme for
operating on a collection of threads atomically.
typedef int (ACE_Thread_Manager::*THR_FUNC)(int, int);
int check_state (ACE_Thread_State state, ACE_thread_t thread);
Efficiently check whether thread is in a particular state.
This call updates the TSS cache if possible to speed up
subsequent searches.
int apply_grp (int grp_id, THR_FUNC, int = 0);
Apply func to all members of the table that match the grp_id.
int apply_all (THR_FUNC, int = 0);
Apply func to all members of the table.
int resume_thr (int i);
Resume the thread at index i.
int suspend_thr (int i);
Suspend the thread at index i.
int kill_thr (int i, int signum);
Send signal signum to the thread at index i.
int cancel_thr (int i);
Set the cancellation flag for the thread at index i.
ACE_Thread_Descriptor *thr_table_;
Vector that describes thread state within the Thread_Manager.
size_t max_table_size_;
Maximum number of threads we can manage (should be dynamically
allocated).
size_t current_count_;
Current number of threads we are managing.
int grp_id_;
Keeps track of the next group id to assign.
ACE_Thread_Mutex and condition variable for synchronizing
termination.
ACE_Thread_Mutex lock_;
ACE_Condition_Thread_Mutex zero_cond_;
AUTHOR
Doug Schmidt
LIBRARY
ace