Tanl Linguistic Pipeline

IXE::ThreadPool Class Reference

A ThreadPool pre-creates and manages a pool of persistent threads to do tasks taken from a queue. More...

#include <ThreadPool.h>

List of all members.

Classes

class  Thread
 A thread is an abstract base class that wraps an OS thread, within a thread pool context, i.e., it does all of the grunt work of waiting for tasks and coordinating with the thread pool object to which it belongs. More...

Public Member Functions

 ThreadPool (char const *process_name, int min_threads, int max_threads, int timeout)
 ThreadPool (char const *process_name, Thread const *prototype, int min_threads, int max_threads, int timeout)
 Construct (initialize) a ThreadPool creating as many threads as requested.
 ~ThreadPool ()
 Destroy a ThreadPool by destroying all the threads in it.
void AddTask (Thread::TaskDescr)
void init (Thread const *prototype)
void Run (int socket_port, int socket_queue_size, unsigned socket_timeout)

Friends

class Thread

Detailed Description

A ThreadPool pre-creates and manages a pool of persistent threads to do tasks taken from a queue.

A thread takes a task off the queue, performs it, then returns to the idle state. Except as noted below, a thread persists forever. This improves performance because a given task does not incur the thread creation/destruction cost.

The pool size grows dynamically when there are more tasks in the queue than threads. Threads will die off if idle past a timeout and the pool will return to its original size. (Which threads die off is indeterminate, i.e., the original set of threads created are not guaranteed to persist forever. Once there are more threads than the original size, all threads are equally likely to die off.)

If you don't want the dynamic behavior, just set maxThreads to be equal to minThreads.

SEE ALSO

Bradford Nichols, Dick Buttlar, and Jacqueline Proulx Farrell. "Pthreads Programming," O'Reilly & Associates, Sebestabol, CA, 1996.


Constructor & Destructor Documentation

IXE::ThreadPool::ThreadPool ( char const *  process_name,
Thread const *  prototype,
int  min_threads,
int  max_threads,
int  timeout 
)

Construct (initialize) a ThreadPool creating as many threads as requested.

Parameters:
prototype A pointer to an instance of a class derived from "thread" used to create new instances of itself.
min_threads The minimum number of threads to keep available.
max_threads The maximum number of threads to allow.
timeout The number of seconds for a thread to wait for a task before committing suicide, but only if more than min_threads presently exist.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
 
Copyright © 2005-2011 G. Attardi. Generated on 4 Mar 2011 by doxygen 1.6.1.