#include <tp_exec.h>
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. |
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.
amino::ThreadPoolExecutor::ThreadPoolExecutor | ( | ) | [inline] |
amino::ThreadPoolExecutor::ThreadPoolExecutor | ( | int | threadNum | ) | [inline] |
Create a thread pool executor which generate a fixed number of threads.
threadNum | number of threads |
virtual amino::ThreadPoolExecutor::~ThreadPoolExecutor | ( | ) | [inline, virtual] |
destructor will delete all internal threads
std::logic_error | when any thread is still working. |
void amino::ThreadPoolExecutor::execute | ( | Runnable * | task | ) | [inline] |
Execute a task with a thread from internal thread pool.
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.
timeOut | timeout in millisecond |
Reimplemented from amino::ExecutorService.
virtual bool amino::ThreadPoolExecutor::finished | ( | ) | [inline, protected, virtual] |
Implements amino::ExecutorService.
friend class WorkerThread [friend] |