amino::ThreadPoolExecutor Class Reference

An executor which pools a fix number of threads. Different tasks can reuse threads among each execution. More...

#include <tp_exec.h>

Inheritance diagram for amino::ThreadPoolExecutor:

amino::ExecutorService

List of all members.

Public Member Functions

 ThreadPoolExecutor ()
 ThreadPoolExecutor (int threadNum)
 Create a thread pool executor which generate a fixed number of threads.
virtual ~ThreadPoolExecutor ()
 destructor will delete all internal threads
void execute (Runnable *task)
 Execute a task with a thread from internal thread pool.
virtual void shutdown ()
 Mark the executor as shutdown state, which mean executor will throw an exception when execute(Runnable*) or submit(Runnable *) are called in future.
virtual void halt ()
 call this method to mark executor as halt. No further tasks can be accepted by the executor. Tasks already submitted but not started will be canceled. TODO: this function shoud return a list of un-started tasks
virtual void waitTermination ()
 Block caller thread until all tasks inside the executor get executed. shutdown() or halt() method must be called before this method.
virtual bool waitTermination (int timeOut)
 Block caller thread until all tasks inside the executor get executed or timeout is reached. Shutdown() or halt() method must be called before this method.

Protected Member Functions

virtual bool finished ()

Friends

class WorkerThread

Classes

class  WorkerThread
 Worker thread contains an infinite loop which fetches and executes tasks from scheduler.


Detailed Description

An executor which pools a fix number of threads. Different tasks can reuse threads among each execution.

This class creates a fix number of threads at startup. Since then, these threads are all blocked waiting for arrival of new tasks. Work stealing scheduler is used internally to ensure efficient task scheduling.


Constructor & Destructor Documentation

amino::ThreadPoolExecutor::ThreadPoolExecutor (  )  [inline]

amino::ThreadPoolExecutor::ThreadPoolExecutor ( int  threadNum  )  [inline]

Create a thread pool executor which generate a fixed number of threads.

Parameters:
threadNum number of threads

virtual amino::ThreadPoolExecutor::~ThreadPoolExecutor (  )  [inline, virtual]

destructor will delete all internal threads

Exceptions:
std::logic_error when any thread is still working.


Member Function Documentation

void amino::ThreadPoolExecutor::execute ( Runnable task  )  [inline]

Execute a task with a thread from internal thread pool.

Exceptions:
std::logic_error when the executor is already shutdown.

virtual void amino::ThreadPoolExecutor::shutdown (  )  [inline, virtual]

Mark the executor as shutdown state, which mean executor will throw an exception when execute(Runnable*) or submit(Runnable *) are called in future.

Implements amino::ExecutorService.

virtual void amino::ThreadPoolExecutor::halt (  )  [inline, virtual]

call this method to mark executor as halt. No further tasks can be accepted by the executor. Tasks already submitted but not started will be canceled. TODO: this function shoud return a list of un-started tasks

Implements amino::ExecutorService.

virtual void amino::ThreadPoolExecutor::waitTermination (  )  [inline, virtual]

Block caller thread until all tasks inside the executor get executed. shutdown() or halt() method must be called before this method.

Reimplemented from amino::ExecutorService.

virtual bool amino::ThreadPoolExecutor::waitTermination ( int  timeOut  )  [inline, virtual]

Block caller thread until all tasks inside the executor get executed or timeout is reached. Shutdown() or halt() method must be called before this method.

Parameters:
timeOut timeout in millisecond
Returns:
true if executor is terminated. Or false if timeout is reached.

Reimplemented from amino::ExecutorService.

virtual bool amino::ThreadPoolExecutor::finished (  )  [inline, protected, virtual]


Friends And Related Function Documentation

friend class WorkerThread [friend]


The documentation for this class was generated from the following file:

Generated on Tue Dec 9 13:39:40 2008 for Amino by  doxygen 1.5.6