Classes | |
class | ExcNoThread |
Public Member Functions | |
Thread (const std_cxx1x::function< RT()> &function) | |
Thread () | |
void | join () const |
RT | return_value () |
bool | operator== (const Thread &t) |
Private Attributes | |
std_cxx1x::shared_ptr < internal::ThreadDescriptor < RT > > | thread_descriptor |
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.
Threads::Thread< RT >::Thread | ( | const std_cxx1x::function< RT()> & | function | ) | [inline] |
Construct a thread object with a function object.
References Threads::Thread< RT >::thread_descriptor.
Threads::Thread< RT >::Thread | ( | ) | [inline] |
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.
void Threads::Thread< RT >::join | ( | ) | const [inline] |
Join the thread represented by this object, i.e. wait for it to finish. You can't call this function if you have used the default constructor of this class and have not assigned a thread object to it.
References AssertThrow, and Threads::Thread< RT >::thread_descriptor.
Referenced by Threads::Thread< RT >::return_value().
RT Threads::Thread< RT >::return_value | ( | ) | [inline] |
Get the return value of the function of the thread. Since this is only available once the thread finishes, this implicitely also calls join()
.
References Threads::Thread< RT >::join(), and Threads::Thread< RT >::thread_descriptor.
bool Threads::Thread< RT >::operator== | ( | const Thread< RT > & | t | ) | [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.
References Threads::Thread< RT >::thread_descriptor.
std_cxx1x::shared_ptr<internal::ThreadDescriptor<RT> > Threads::Thread< RT >::thread_descriptor [private] |
Shared pointer to the object representing the thread, and abstracting operating system functions to work on it. Boost's shared pointer implementation will make sure that that object lives as long as there is at least one subscriber to it.
Note that since the descriptor holds the location where the return value is stored, even if all Threads::Thread objects that point to the descriptor go out of scope, we must make sure that the descriptor is not yet destroyed. Rather, the descriptor must be destroyed when the last Threads::Thread object that points to it goes out of scope or whenever the thread is finished, whatever happens later. 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.
Referenced by Threads::Thread< RT >::join(), Threads::Thread< RT >::operator==(), Threads::Thread< RT >::return_value(), and Threads::Thread< RT >::Thread().