RSC
0.16.0
|
A task is a self.contained piece of work that can be executed by another thread. More...
#include <Task.h>
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... | |
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.
|
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.
|
pure virtual |
Tells whether the task was interrupted by a call to cancel.
true
if cancel was called, else false
Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.
|
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.
true
if run will not perform anything anymore Implemented in rsc::threading::RepetitiveTask, and rsc::threading::SimpleTask.
|
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.
|
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.