deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
Threads::Task< RT >::TaskData Class Reference

Public Member Functions

 TaskData (std::future< RT > &&future) noexcept
 
 TaskData (const TaskData &)=delete
 
 TaskData (TaskData &&)=delete
 
TaskDataoperator= (const TaskData &)=delete
 
TaskDataoperator= (TaskData &&)=delete
 
 ~TaskData () noexcept
 
void wait ()
 
internal::return_value< RT >::reference_type get ()
 

Private Attributes

std::mutex mutex
 
std::future< RT > future
 
std::atomic< booltask_has_finished
 
internal::return_value< RT > returned_object
 
std::unique_ptr< tbb::task_group > task_group
 

Friends

class Task< RT >
 

Detailed Description

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

A data structure that holds a std::future into which the task deposits its return value. Since one can only call std::future::get() once, we do so in the get() member function and then move the returned object into the returned_object member variable from where we can read it multiple times and from where it can also be moved away if it is not copyable.

Definition at line 848 of file thread_management.h.

Constructor & Destructor Documentation

◆ TaskData() [1/3]

template<typename RT = void>
Threads::Task< RT >::TaskData::TaskData ( std::future< RT > &&  future)
inlinenoexcept

Constructor. Initializes an std::future object and assumes that the task so set has not finished yet.

Definition at line 855 of file thread_management.h.

◆ TaskData() [2/3]

template<typename RT = void>
Threads::Task< RT >::TaskData::TaskData ( const TaskData )
delete

There can only be one TaskData object referencing a task. Make sure that these objects are not copied.

◆ TaskData() [3/3]

template<typename RT = void>
Threads::Task< RT >::TaskData::TaskData ( TaskData &&  )
delete

There can only be one TaskData object referencing a task. Make sure that these objects are not moved.

◆ ~TaskData()

template<typename RT = void>
Threads::Task< RT >::TaskData::~TaskData ( )
inlinenoexcept

Destructor. Wait for the results to be ready. This ensures that the last Task object holding a shared pointer to the current TaskData object blocks until the task has actually finished – in essence, this makes sure that one cannot just abandon a task completely by letting all Task objects that point to it go out of scope.

Definition at line 896 of file thread_management.h.

Member Function Documentation

◆ operator=() [1/2]

template<typename RT = void>
TaskData & Threads::Task< RT >::TaskData::operator= ( const TaskData )
delete

There can only be one TaskData object referencing a task. Make sure that these objects are not copied.

◆ operator=() [2/2]

template<typename RT = void>
TaskData & Threads::Task< RT >::TaskData::operator= ( TaskData &&  )
delete

There can only be one TaskData object referencing a task. Make sure that these objects are not moved.

◆ wait()

template<typename RT = void>
void Threads::Task< RT >::TaskData::wait ( )
inline

Wait for the std::future object to be ready, i.e., for the time when the std::promise receives its value. If this has already happened, this function can follow a fast path.

Definition at line 935 of file thread_management.h.

◆ get()

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

Definition at line 1064 of file thread_management.h.

Friends And Related Symbol Documentation

◆ Task< RT >

template<typename RT = void>
friend class Task< RT >
friend

Definition at line 1117 of file thread_management.h.

Member Data Documentation

◆ mutex

template<typename RT = void>
std::mutex Threads::Task< RT >::TaskData::mutex
private

A mutex used to synchronize access to the data structures of this class.

Definition at line 1075 of file thread_management.h.

◆ future

template<typename RT = void>
std::future<RT> Threads::Task< RT >::TaskData::future
private

The promise associated with the task that is represented by the current class.

Definition at line 1081 of file thread_management.h.

◆ task_has_finished

template<typename RT = void>
std::atomic<bool> Threads::Task< RT >::TaskData::task_has_finished
private

A boolean indicating whether the task in question has finished.

Note
We are using a std::atomic_bool here because we have to make sure that concurrent reads and stores between threads are properly synchronized, and that sequential reads on a given thread are not reordered or optimized away. A std::atomic [1] achieves this because (if not otherwise annotated) reads and stores to the boolean are subject to the std::memory_order_seq_cst memory ordering [2]. This ensures that Schmidt's double checking does indeed work. For additional information (and a potentially more efficient implementation) see [3].

[1] https://en.cppreference.com/w/cpp/atomic/atomic [2] https://en.cppreference.com/w/cpp/atomic/memory_order [3] https://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/

Definition at line 1101 of file thread_management.h.

◆ returned_object

template<typename RT = void>
internal::return_value<RT> Threads::Task< RT >::TaskData::returned_object
private

The place where the returned value is moved to once the std::future has delivered.

Definition at line 1107 of file thread_management.h.

◆ task_group

template<typename RT = void>
std::unique_ptr<tbb::task_group> Threads::Task< RT >::TaskData::task_group
private

A task group object we can wait for. This object is created in the constructor, and is removed as soon as we have determined that the task has finished, so as to free any resources the TBB may still be holding in order to allow programs to still check on the status of a task in this group.

Definition at line 1117 of file thread_management.h.


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