RSC  0.17.1
rsc::threading::Task Class Referenceabstract

A task is a self.contained piece of work that can be executed by another thread. More...

#include <Task.h>

Inheritance diagram for rsc::threading::Task:
Inheritance graph
Collaboration diagram for rsc::threading::Task:
Collaboration graph

Public Member Functions

virtual ~Task ()
 
virtual void cancel ()=0
 Interrupts the task as soon as possible. More...
 
virtual bool isCancelRequested ()=0
 Tells whether the task was interrupted by a call to cancel. More...
 
virtual void run ()=0
 Performs the real task work. More...
 
virtual bool isDone ()=0
 Indicates whether the task finished execution, either through being canceled or through successfully ending. More...
 
virtual void waitDone ()=0
 Waits for the execution of this task to finish. More...
 

Detailed Description

A task is a self.contained piece of work that can be executed by another thread.

Tasks can be canceled and interested clients can wait until a task has finished its work.

In this context a task is done whenever it's execution finished. This includes cancellation.

If your interruption logic does not requires asynchronous method invocations and determining the done state is easy, you can use SimpleTask.

Author
swrede
jwienke

Definition at line 52 of file Task.h.

Constructor & Destructor Documentation

rsc::threading::Task::~Task ( )
virtual

Definition at line 36 of file Task.cpp.

Member Function Documentation

virtual void rsc::threading::Task::cancel ( )
pure virtual

Interrupts the task as soon as possible.

Will, at some time, wake up waiting threads in waitDone.

Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.

virtual bool rsc::threading::Task::isCancelRequested ( )
pure virtual

Tells whether the task was interrupted by a call to cancel.

Returns
true if cancel was called, else false

Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.

virtual bool rsc::threading::Task::isDone ( )
pure virtual

Indicates whether the task finished execution, either through being canceled or through successfully ending.

If true is returned, the run method of this task will not perform anything anymore.

Returns
true if run will not perform anything anymore

Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.

virtual void rsc::threading::Task::run ( )
pure virtual

Performs the real task work.

Should check for canceling as often as possible. After completion or cancellation, isDone must return and waiting threads in waitDone must be waked up.

It is a good practice to check for cancellation as a first step in the implementation of this method in order to exit fast if the task was canceled before it actually started running.

Implemented in rsc::threading::RepetitiveTask.

virtual void rsc::threading::Task::waitDone ( )
pure virtual

Waits for the execution of this task to finish.

This may either be caused by a successful completion of the task or by being canceled. This method must block until run exits or it is sure that run will not be called anymore.

Undefined behavior might occur if this method is called before the task is scheduled. I.e. a calling thread might block infinitely.

Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.


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