Reference documentation for deal.II version 9.1.0-pre
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members

#include <deal.II/base/thread_management.h>

Public Member Functions

 Task (const std::function< RT()> &function_object)
 
 Task (const Task< RT > &t)
 
 Task ()=default
 
void join () const
 
bool joinable () const
 
internal::return_value< RT >::reference_type return_value ()
 
bool operator== (const Task &t) const
 

Static Public Member Functions

static::ExceptionBase & ExcNoTask ()
 

Private Attributes

std::shared_ptr< internal::TaskDescriptor< RT > > task_descriptor
 

Detailed Description

template<typename RT = void>
class Threads::Task< RT >

Describes one task object based on the Threading Building Blocks' Task. Note that the call to join() must be executed on the same thread as the call to the constructor. Otherwise, there might be a deadlock. In other words, a Task object should never passed on to another task for calling the join() method.

Author
Wolfgang Bangerth, 2009

Definition at line 1389 of file thread_management.h.

Constructor & Destructor Documentation

template<typename RT = void>
Threads::Task< RT >::Task ( const std::function< RT()> &  function_object)
inline

Construct a task object given a function object to execute on the task, and then schedule this function for execution.

Postcondition
Using this constructor automatically makes the task object joinable().

Definition at line 1719 of file thread_management.h.

template<typename RT = void>
Threads::Task< RT >::Task ( const Task< RT > &  t)
inline

Copy constructor.

Postcondition
Using this constructor automatically makes the task object joinable().

Definition at line 1735 of file thread_management.h.

template<typename RT = void>
Threads::Task< RT >::Task ( )
default

Default constructor. You can't do much with a task object constructed this way, except for assigning it a task object that holds data created by the Threads::new_task() functions.

Postcondition
Using this constructor leaves the object in an unjoinable state, i.e., joinable() will return false.

Member Function Documentation

template<typename RT = void>
void Threads::Task< RT >::join ( ) const
inline

Join the task represented by this object, i.e. wait for it to finish.

A task can be joined multiple times (while the first join() operation may block until the task has completed running, all successive attempts to join will return immediately).

Precondition
You can't call this function if you have used the default constructor of this class and have not assigned a task object to it. In other words, the function joinable() must return true.

Definition at line 1762 of file thread_management.h.

template<typename RT = void>
bool Threads::Task< RT >::joinable ( ) const
inline

Return whether the current object can be joined. You can join a task object once a task (typically created with Threads::new_task()) has actually been assigned to it. On the other hand, the function returns false if the object has been default constructed.

A task can be joined multiple times (while the first join() operation may block until the task has completed running, all successive attempts to join will return immediately). Consequently, if this function returns true, it will continue to return true until the task object it reports on is assigned to from another object.

Definition at line 1781 of file thread_management.h.

template<typename RT = void>
internal::return_value<RT>::reference_type Threads::Task< RT >::return_value ( )
inline

Get the return value of the function of the task. Since it is only available once the thread finishes, this function internally also calls join(). You can call this function multiple times as long as the object refers to the same task, and expect to get the same return value every time. (With the exception of the case where the returned object has been moved; see below.)

Note
The function returns a non-const reference to the returned object, instead of the returned object. This allows writing code such as
Threads::Task<int> t = Threads::new_task (...function returning an
int...); t.return_value() = 42; // overwrite returned value int i =
t.return_value(); // i is now 42
You will rarely have a need to write such code. On the other hand, the function needs to return a writable (non-const) reference to support code such as this:
std::unique_ptr<int> create_int (const std::string &s) { ... }
void f()
{
t = Threads::new_task (&create_int, "42");
std::unique_ptr<int> i = std::move(t.return_value());
...
}
Here, it is necessary to std::move the returned object (namely, the std::unique_ptr object) because std::unique_ptr objects can not be copied. In other words, to get the pointer out of the object returned from the task, it needs to be moved, and in order to be moved, the current function needs to return a writable (non-const) reference.
Precondition
You can't call this function if you have used the default constructor of this class and have not assigned a task object to it. In other words, the function joinable() must return true.

Definition at line 1832 of file thread_management.h.

template<typename RT = void>
bool Threads::Task< RT >::operator== ( const Task< RT > &  t) const
inline

Check for equality of task objects. Since objects of this class store an implicit pointer to an object that exists exactly once for each task, the check is simply to compare these pointers.

Definition at line 1845 of file thread_management.h.

Member Data Documentation

template<typename RT = void>
std::shared_ptr<internal::TaskDescriptor<RT> > Threads::Task< RT >::task_descriptor
private

Shared pointer to the object representing the task. This makes sure that the object lives as long as there is at least one subscriber to it.

Definition at line 1869 of file thread_management.h.


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