Public Member Functions | |
void | start (const std_cxx1x::function< RT()> &function) |
void | join () |
Public Attributes | |
std_cxx1x::shared_ptr < ThreadDescriptor< RT > > | self |
std_cxx1x::thread | thread |
return_value< RT > | ret_val |
Static Private Member Functions | |
static void | thread_entry_point (const std_cxx1x::function< RT()> function, ThreadDescriptor< RT > *descriptor) |
While we have only one of these objects per thread, several Threads::Thread objects may refer to this descriptor.
Note, however, that since this object holds the location where we store the return value of the thread, the object has to live at least as long as the thread executes. This means that even if all Threads::Thread objects that refered to this descriptor (through a std::shared_ptr) have gone out of scope, we must still hold on to the object. We do this by having the descriptor keep a pointer to itself and reset it to zero once it is done -- effectly keeping the use pointer above zero as long as work is going on.
To enable the current class to obtain a shared_ptr from itself, we derive from the class std::enable_shared_from_this.
void Threads::internal::ThreadDescriptor< RT >::start | ( | const std_cxx1x::function< RT()> & | function | ) | [inline] |
Start the thread and let it put its return value into the ret_val object.
Note that we cannot already do this in the constructor of this class: we will call enable_shared_from_this::shared_from_this which requires that there is already a shared_ptr that owns this object; however, at the time of creation, there can of course be no shared_ptr that owns the object -- it is, after all, just being created and can not already have been handed off to a shared_ptr; as a consequence, we first create the object, give it to a shared_ptr, and then call shared_from_this.
References Threads::internal::ThreadDescriptor< RT >::thread, and Threads::internal::ThreadDescriptor< RT >::thread_entry_point().
void Threads::internal::ThreadDescriptor< RT >::join | ( | ) | [inline] |
Wait for the thread to end.
References Threads::internal::ThreadDescriptor< RT >::thread.
static void Threads::internal::ThreadDescriptor< RT >::thread_entry_point | ( | const std_cxx1x::function< RT()> | function, | |
ThreadDescriptor< RT > * | descriptor | |||
) | [inline, static, private] |
The function that runs on the thread.
References Assert, Threads::internal::call(), Threads::internal::ThreadDescriptor< RT >::ret_val, and Threads::internal::ThreadDescriptor< RT >::self.
Referenced by Threads::internal::ThreadDescriptor< RT >::start().
std_cxx1x::shared_ptr<ThreadDescriptor<RT> > Threads::internal::ThreadDescriptor< RT >::self |
A pointer to the current object, kept nonzero as long as the thread is executing to avoid destroying the current object while we are still expecting to write something into the return value location.
Referenced by Threads::internal::ThreadDescriptor< RT >::thread_entry_point().
std_cxx1x::thread Threads::internal::ThreadDescriptor< RT >::thread |
An object that represents the thread started.
Referenced by Threads::internal::ThreadDescriptor< RT >::join(), and Threads::internal::ThreadDescriptor< RT >::start().
return_value<RT> Threads::internal::ThreadDescriptor< RT >::ret_val |
An object that will hold the value returned by the function called on the thread.
Referenced by Threads::internal::ThreadDescriptor< RT >::thread_entry_point().