If you can read this text, it means you are not experiencing this website at its best. This website is designed for used with a standards-compliant browser.
Current version: 2.3.2
ZThreads
A platform-independent, multi-threading and synchronization library for C++
Home Documentation Downloads CVS Contact
PoolExecutor Class Reference

#include <PoolExecutor.h>

Inheritance diagram for PoolExecutor:
Executor Cancelable Waitable NonCopyable

Public Member Functions

 PoolExecutor (size_t n)
 
virtual ~PoolExecutor ()
 Destroy a PoolExecutor.
 
virtual void interrupt ()
 
void size (size_t n)
 
size_t size ()
 
virtual void execute (const Task &task)
 
virtual void cancel ()
 
virtual bool isCanceled ()
 
virtual void wait ()
 
virtual bool wait (unsigned long timeout)
 
virtual void interrupt ()=0
 
virtual void execute (const Task &task)=0
 
- Public Member Functions inherited from Cancelable
virtual ~Cancelable ()
 Destroy a Cancelable object.
 
virtual void cancel ()=0
 
virtual bool isCanceled ()=0
 
- Public Member Functions inherited from Waitable
virtual ~Waitable ()
 Destroy a Waitable object.

 
virtual void wait ()=0
 
virtual bool wait (unsigned long timeout)=0
 

Detailed Description

Author
Eric Crahen http://www.code-foo.com
Date
<2003-07-16T22:41:07-0400>
Version
2.3.0

A PoolExecutor spawns a set of threads that are used to run tasks that are submitted in parallel. A PoolExecutor supports the following optional operations,

  • cancel()ing a PoolExecutor will cause it to stop accepting new tasks.
  • interrupt()ing a PoolExecutor will cause the any thread running a task which was submitted prior to the invocation of this function to be interrupted during the execution of that task.
  • wait()ing on a PoolExecutor will block the calling thread until all tasks that were submitted prior to the invocation of this function have completed.
See also
Executor.

Constructor & Destructor Documentation

◆ PoolExecutor()

PoolExecutor ( size_t  n)

Create a PoolExecutor

Parameters
nnumber of threads to service tasks with

Member Function Documentation

◆ cancel()

virtual void cancel ( )
virtual
See also
Cancelable::cancel()

Implements Cancelable.

◆ execute()

virtual void execute ( const Task task)
virtual

Submit a task to this Executor.

This will not block the calling thread very long. The submitted task will be executed at some later point by another thread.

Parameters
taskTask to be run by a thread managed by this executor
Precondition
The Executor should have been canceled prior to this invocation.
Postcondition
The submitted task will be run at some point in the future by this Executor.
Exceptions
Cancellation_Exceptionthrown if the Executor was canceled prior to the invocation of this function.
See also
PoolExecutor::cancel()
Executor::execute(const Task& task)

Implements Executor.

◆ interrupt()

virtual void interrupt ( )
virtual

Invoking this function causes each task that had been submitted prior to this function to be interrupted. Tasks submitted after the invocation of this function are unaffected.

Postcondition
Any task submitted prior to the invocation of this function will be run in the context of an interrupted thread.
Any thread already executing a task which was submitted prior to the invocation of this function will be interrupted.

Implements Executor.

◆ isCanceled()

virtual bool isCanceled ( )
virtual
See also
Cancelable::isCanceled()

Implements Cancelable.

◆ size() [1/2]

size_t size ( )

Get the current number of threads being used to execute submitted tasks.

Returns
n number of worker threads.

◆ size() [2/2]

void size ( size_t  n)

Alter the number of threads being used to execute submitted tasks.

Parameters
nnumber of worker threads.
Precondition
n must be greater than 0.
Postcondition
n threads will be executing tasks submitted to this executor.
Exceptions
InvalidOp_Exceptionthrown if the new number of threads n is less than 1.

◆ wait() [1/2]

virtual void wait ( )
virtual

Block the calling thread until all tasks submitted prior to this invocation complete.

Exceptions
Interrupted_Exceptionthrown if the calling thread is interrupted before the set of tasks being wait for can complete.
See also
Waitable::wait()

Implements Waitable.

◆ wait() [2/2]

virtual bool wait ( unsigned long  timeout)
virtual

Block the calling thread until all tasks submitted prior to this invocation complete or until the calling thread is interrupted.

Parameters
timeoutmaximum amount of time, in milliseconds, to wait for the currently submitted set of Tasks to complete.
Exceptions
Interrupted_Exceptionthrown if the calling thread is interrupted before the set of tasks being wait for can complete.
Returns
  • true if the set of tasks being wait for complete before timeout milliseconds elapse.
  • false otherwise.
See also
Waitable::wait(unsigned long timeout)

Implements Waitable.


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