MetriVis Overview | Download | User Manual | Development
Reference Overview | Design Documentation | Reference Backend | Reference Frontend

metrivis::RequestHandler< T, ID >::ThreadPool< S > Class Template Reference

ThreadPool contains a set of worker threads. More...


Public Member Functions

 ThreadPool (int number_of_threads)
 Constructor initializes a thread pool of a given size.
 ~ThreadPool ()
 Deconstructor.
void PushRequest (const RequestDescription &request_description)
 Schedules a HTTP request to be handeled in this pipeline.
void ScheduleRequestsManually ()
 Forces the ThreadPool to schedule pending requests manually.
void Terminate ()
 Removes all pending requests and waits until all jobs finished.

Protected Member Functions

const
RequestDescription
PopRequest () const
 Gets the next RequestDescription for execution.

Private Member Functions

void ScheduleRequests ()
 Schedules pending requests into the FIFO worker queue.
void ProcessRequest ()
 Processes a request.

Private Attributes

boost::threadpool::pool pool_
 Internal thread pool.
std::queue
< RequestDescription
request_desriptions_
 requests.
boost::mutex dispatcher_mutex_
 Mutex for locking dispatcher_.
std::stack< S * > dispatchers_
 Stack of dispatcher for each thread.
bool post_mortem_
 Indicates if the pool is terminated.


Detailed Description

template<class T, int ID = -1>
template<class S>
class metrivis::RequestHandler< T, ID >::ThreadPool< S >

ThreadPool contains a set of worker threads.

In the thread pool pattern in programming, a number of N threads are created to perform a number of M tasks, usually organized in a queue. Typically, N << M. As soon as a thread completes its task, it will request the next task from the queue until all tasks have been completed. The thread can then terminate, or sleep until there are new tasks available. (snippet from Wikipedia, the free encyclopedia).

This class is not recyclable. Once it is deleted it wont be able to resurrect. After ThreadPool::Terminate is called the object can't be used anymore.


Constructor & Destructor Documentation

template<class T, int ID = -1>
template<class S>
metrivis::RequestHandler< T, ID >::ThreadPool< S >::ThreadPool ( int  number_of_threads  )  [inline]

Constructor initializes a thread pool of a given size.

Parameters:
number_of_threads,: The number of threads to be contained.

template<class T, int ID = -1>
template<class S>
metrivis::RequestHandler< T, ID >::ThreadPool< S >::~ThreadPool (  )  [inline]

Deconstructor.

The ThreadPool should be stopped first with ThreadPool::Terminate function.


Member Function Documentation

template<class T, int ID = -1>
template<class S>
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::PushRequest ( const RequestDescription request_description  )  [inline]

Schedules a HTTP request to be handeled in this pipeline.

Parameters:
request_description,: The HTTP request description object.
This will just injects all pending requests into the ThreadPool. The requests will be handedled as soon as there are free worker threads available.

template<class T, int ID = -1>
template<class S>
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ScheduleRequestsManually (  )  [inline]

Forces the ThreadPool to schedule pending requests manually.

This will just injects all pending requests into the ThreadPool. The requests will be handedled as soon as there are free worker threads available. This shouldn't be needed to call since new requests are automatically scheduled.

template<class T, int ID = -1>
template<class S>
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::Terminate (  )  [inline]

Removes all pending requests and waits until all jobs finished.

Blocks until all resources are freed again.

Todo:
pool_.wait should check how long it has been hanging. To see if a pipeline is not finishing at all.

template<class T, int ID = -1>
template<class S>
const RequestDescription& metrivis::RequestHandler< T, ID >::ThreadPool< S >::PopRequest (  )  const [inline, protected]

Gets the next RequestDescription for execution.

Returns:
The next request in line.

template<class T, int ID = -1>
template<class S>
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ScheduleRequests (  )  [inline, private]

Schedules pending requests into the FIFO worker queue.

Adds the request to the thread pool. Requests will be handeled in a FIFO way.

template<class T, int ID = -1>
template<class S>
void metrivis::RequestHandler< T, ID >::ThreadPool< S >::ProcessRequest (  )  [inline, private]

Processes a request.

This function is registered as the running function for all threads spawned in this thread pool.

Todo:
remove this waiting stuff.


The documentation for this class was generated from the following file:
Generated on Fri Feb 29 16:47:20 2008 for MetriVis by  doxygen 1.5.3