Reference documentation for deal.II version 9.4.1
|
#include <deal.II/base/thread_management.h>
Public Member Functions | |
ThreadDescriptor () | |
~ThreadDescriptor () | |
void | start (const std::function< RT()> &function) |
void | join () |
Public Attributes | |
std::thread | thread |
std::shared_ptr< return_value< RT > > | ret_val |
std::atomic< bool > | thread_is_active |
Mutex | thread_is_active_mutex |
Static Private Member Functions | |
static void | thread_entry_point (const std::function< RT()> &function, std::shared_ptr< return_value< RT > > ret_val) |
A class that represents threads. For each thread, we create exactly one of these objects – exactly one because it carries the returned value of the function called on the thread.
While we have only one of these objects per thread, several Threads::Thread objects may refer to this descriptor. If all Thread objects go out of scope the ThreadDescriptor will detach from the thread before being destroyed.
Definition at line 416 of file thread_management.h.
|
inline |
Default constructor.
Definition at line 478 of file thread_management.h.
|
inline |
Definition at line 482 of file thread_management.h.
|
inline |
Start the thread and let it put its return value into the ret_val object.
Definition at line 495 of file thread_management.h.
|
inline |
Wait for the thread to end.
Definition at line 507 of file thread_management.h.
|
inlinestaticprivate |
The function that runs on the thread.
Definition at line 529 of file thread_management.h.
std::thread Threads::internal::ThreadDescriptor< RT >::thread |
An object that represents the thread started.
Definition at line 421 of file thread_management.h.
std::shared_ptr<return_value<RT> > Threads::internal::ThreadDescriptor< RT >::ret_val |
An object that will hold the value returned by the function called on the thread.
The return value is stored in a shared_ptr because we might abandon the ThreadDescriptor. This makes sure the object stays alive until the thread exits.
Definition at line 431 of file thread_management.h.
std::atomic<bool> Threads::internal::ThreadDescriptor< RT >::thread_is_active |
An atomic bool variable that is initially false, is set to true when a new thread is started, and is set back to false once join() has been called.
We use this variable to make sure we can call join() twice on the same thread. For some reason, the C++ standard library throws a std::system_error exception if one tries to call std::thread::join twice (and in fact, before the second call, std::thread::joinable returns false) but this is a somewhat desirable thing to do because one doesn't have to keep track whether join() has been called before. Using this variable, whenever we have called join() before, the variable is set to true and we can skip over calling std::thread::join() a second time. Access to this variable is guarded by the following mutex.
pthread_join
appear to have this requirement any more. Consequently, we can in fact join from different threads and we test this in base/thread_validity_07.Definition at line 468 of file thread_management.h.
Mutex Threads::internal::ThreadDescriptor< RT >::thread_is_active_mutex |
Mutex guarding access to the previous variable.
Definition at line 473 of file thread_management.h.