Tanl Linguistic Pipeline

IXE::ThreadPool::Thread Class Reference

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...

#include <ThreadPool.h>

List of all members.

Classes

union  TaskDescr

Public Member Functions

void Start ()
 Causes this thread to begin execution, calling its Run() method.

Protected Member Functions

 Thread (ThreadPool &)
 Construct a thread object, passing it a pointer to ourselves.
virtual ~Thread ()
 Destroy a thread.
virtual Threadclone (ThreadPool &) const =0
 Used to create another thread to add to the pool.
virtual void Run (TaskDescr)=0
 Thread (Thread const &)
 forbid copy
Threadoperator= (Thread const &)
 forbid assignment

Static Protected Member Functions

static TRESULT Main (void *)
 Main function for the OS thread, which invokes Run().
static void Destroy (void *p)
 Data cleanup handler, called upon thread termination.

Protected Attributes

pthread_t thread
 our POSIX thread
ThreadPoolpool
 to which we belong
bool destroying
 within Destroy()

Friends

class ThreadPool

Detailed Description

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.

The derived class must override the pure virtual member function Run(). The Run() function gets invoked with an argument taken from the task queue.


Constructor & Destructor Documentation

IXE::ThreadPool::Thread::Thread ( ThreadPool p  )  [protected]

Construct a thread object, passing it a pointer to ourselves.

Start() must be called for the thread become active.


Member Function Documentation

void IXE::ThreadPool::Thread::Destroy ( void *  p  )  [static, protected]

Data cleanup handler, called upon thread termination.

This is the clean-up function that gets called upon a thread's death, but only in case the derived class calls ThreadExit() directly.

We must ensure that the thread destructor gets called.

NOTE

This function is declared extern "C" since it is called via the C library function pthread_cleanup_push() and, because it's a C function, it expects C linkage.

Parameters:
p Pointer to an instance of a ThreadPool::Thread.

References destroying, and pool.

Referenced by Main().

TRESULT IXE::ThreadPool::Thread::Main ( void *  p  )  [static, protected]

Main function for the OS thread, which invokes Run().

This is the starting point of execution for a thread.

It waits for a task to appear in its thread pool's task queue and performs the task. After completion, it waits for the next task.

If more threads currently exist than the minimum requested (because more were created as a result of a high request load), then only wait a finite amount of time for a task to appear. If no task appears in that amount of time, then the request load must've lessened so we can destroy this thread.

NOTE

This function is declared extern "C" since it is called via the C library function pthread_create() and, because it's a C function, it expects C linkage.

Parameters:
p Pointer to an instance of a ThreadPool::Thread.
Returns:
This function never returns. It goes away only when the thread is destroyed.

References Destroy(), pool, and thread.

Referenced by Start().

void IXE::ThreadPool::Thread::Start (  ) 

Causes this thread to begin execution, calling its Run() method.

Initialize the thread.

References Main(), pool, and thread.


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.