Reference documentation for deal.II version 9.4.1
|
#include <deal.II/base/thread_management.h>
Public Member Functions | |
Thread (const std::function< RT()> &function) | |
Thread ()=default | |
Thread (const Thread< RT > &t) | |
void | join () const |
internal::return_value< RT >::reference_type | return_value () |
bool | valid () const |
bool | operator== (const Thread &t) const |
Private Attributes | |
std::shared_ptr< internal::ThreadDescriptor< RT > > | thread_descriptor |
An object that represents a spawned thread. This object can be freely copied around in user space, and all instances will represent the same thread and can require to wait for its termination and access its return value.
Threads can be abandoned, i.e. if you just call Threads::new_thread but don't care about the returned object, or if you assign the return Threads::Thread object to an object that subsequently goes out of scope, then the thread previously created will still continue to do work. You will simply not be able to access its return value any more, and it may also happen that your program terminates before the thread has finished its work.
The default value of the template argument is void
, so if the function you are calling on a new thread has no return value, you can omit the template argument.
Definition at line 581 of file thread_management.h.
|
inline |
Construct a thread object with a function object.
Definition at line 588 of file thread_management.h.
|
default |
Default constructor. You can't do much with a thread object constructed this way, except for assigning it a thread object that holds data created by the new_thread() functions.
|
inline |
Copy constructor.
Definition at line 607 of file thread_management.h.
|
inline |
Join the thread represented by this object, i.e. wait for it to finish. If you have used the default constructor of this class and have not assigned a thread object to it, then this function is a no-op.
Definition at line 617 of file thread_management.h.
|
inline |
Get the return value of the function of the thread. 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.)
const
reference to the returned object, instead of the returned object. This allows writing code such as const
) reference to support code such as this: 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 thread, it needs to be moved, and in order to be moved, the current function needs to return a writable (non-const
) reference. Definition at line 667 of file thread_management.h.
|
inline |
Return true if this object has had a thread associated with it, either by using the non-default constructor or by assignment.
Definition at line 678 of file thread_management.h.
|
inline |
Check for equality of thread objects. Since objects of this class store an implicit pointer to an object that exists exactly once for each thread, the check is simply to compare these pointers.
Definition at line 690 of file thread_management.h.
|
private |
Shared pointer to the object representing the thread, and abstracting operating system functions to work on it. This also makes sure that the object lives as long as there is at least one subscriber to it.
Definition at line 701 of file thread_management.h.