Threads::internal::ThreadDescriptor< RT > Struct Template Reference

Inheritance diagram for Threads::internal::ThreadDescriptor< RT >:

Inheritance graph
[legend]

List of all members.

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)


Detailed Description

template<typename RT>
struct Threads::internal::ThreadDescriptor< RT >

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.

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.


Member Function Documentation

template<typename RT>
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().

template<typename RT>
void Threads::internal::ThreadDescriptor< RT >::join (  )  [inline]

Wait for the thread to end.

References Threads::internal::ThreadDescriptor< RT >::thread.

template<typename RT>
static void Threads::internal::ThreadDescriptor< RT >::thread_entry_point ( const std_cxx1x::function< RT()>  function,
ThreadDescriptor< RT > *  descriptor 
) [inline, static, private]


Member Data Documentation

template<typename RT>
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().

template<typename RT>
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().

template<typename RT>
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().


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

deal.II documentation generated on Sat Aug 15 16:52:49 2009 by doxygen 1.5.9