class to hold a dependent asynchronous task with shared ownership More...
#include <taskflow/core/async_task.hpp>
Public Member Functions | |
| AsyncTask ()=default | |
| constructs an empty task handle | |
| ~AsyncTask () | |
| destroys the managed dependent-async task if this is the last owner | |
| AsyncTask (const AsyncTask &rhs) | |
constructs a dependent-async task that shares ownership of rhs | |
| AsyncTask (AsyncTask &&rhs) | |
move-constructs an dependent-async task from rhs | |
| AsyncTask & | operator= (const AsyncTask &rhs) |
copy-assigns the dependent-async task from rhs | |
| AsyncTask & | operator= (AsyncTask &&rhs) |
move-assigns the dependent-async task from rhs | |
| bool | empty () const |
| checks if this dependent-async task is associated with any task | |
| void | reset () |
release the managed object of this | |
| size_t | hash_value () const |
| obtains the hashed value of this dependent-async task | |
| size_t | use_count () const |
| returns the number of shared owners that are currently managing this dependent-async task | |
| bool | is_done () const |
| checks if this dependent-async task finishes | |
| std::exception_ptr | exception_ptr () const |
| retrieves the exception pointer of this task | |
| bool | has_exception_ptr () const |
| queries if the task has an exception pointer | |
Friends | |
| class | Executor |
class to hold a dependent asynchronous task with shared ownership
A tf::AsyncTask is a lightweight handle that retains shared ownership of a dependent asynchronous (dependent-async) task created by an executor. This shared ownership ensures that the dependent-async task remains alive when adding it to the dependency list of another dependent-async task, thus avoiding the classical ABA problem.
tf::AsyncTask is implemented based on the logic of C++ smart pointer std::shared_ptr and is considered cheap to copy or move as long as only a handful of objects own it. When a worker completes an async task, it will remove the task from the executor, decrementing the number of shared owners by one. If that counter reaches zero, the task is destroyed.
|
inline |
checks if this dependent-async task is associated with any task
An empty dependent-async task is not associated with any task created from the executor.
|
inline |
retrieves the exception pointer of this task
This method retrieves the exception pointer of the task, if any, that was silently caught by the executor. For example, the code below retrieves the exception pointer of a dependent-async task that does not have a shared state to propagate its exception.
|
inline |
queries if the task has an exception pointer
The method checks whether the task holds a pointer to a silently caught exception.
|
inline |
obtains the hashed value of this dependent-async task
|
inline |
checks if this dependent-async task finishes
In a multithreaded environment, is_done atomically retrieves (with memory_order_acquire load) the underlying state bit that indicates the completion of this dependent-async task. If the dependent-async task is empty, returns true.
move-assigns the dependent-async task from rhs
Releases the managed object of this and takes over the ownership of rhs.
copy-assigns the dependent-async task from rhs
Releases the managed object of this and retains a new shared ownership of rhs.
|
inline |
release the managed object of this
Releases the ownership of the managed task, if any. After the call *this manages no task.
|
inline |
returns the number of shared owners that are currently managing this dependent-async task
In a multithreaded environment, use_count atomically retrieves (with memory_order_relaxed load) the number of tf::AsyncTask instances that manage the current task.