Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

AttachedThread Class Reference

Platform independent joinable thread. More...

#include <cxxtools/thread.h>

Inheritance diagram for AttachedThread:

Thread List of all members.

Public Member Functions

 AttachedThread (const Callable< void > &cb)
 Contructs a thread with a thread entry.
 ~AttachedThread ()
 Joins the thread, if not already joined.
void join ()
 Wait explicitly for the thread to terminate.
void terminate ()
 Terminates the thread.

Detailed Description

AttachedThreads are threads, which are managed by the creator, and are normally created on the stack. The creator must wait, until the thread terminates either explicitly by calling join() or implicitly by the destructor. The life-time of the callable object must exceed the life-time of the thread. Mind the order of destruction if the AttachedThread is a member variable of a class.

Example:

        struct Operation
        {
            void run()
            {
                // implement, whatever needs to be done in parallel
            }
        };

        int main()
        {
            Operation op;
            cxxtools::Thread thread( cxxtools::callable(op, &Operation::run) );
            thread.start();

            // the thread runs and we can do something else in parallel

            doMoreWork();

            // the thread's destructor waits for the thread to join
            // the op object outlives the thread object
            return 0;
        }


Constructor & Destructor Documentation

AttachedThread ( const Callable< void > &  cb  )  [explicit]

Constructs a thread object to execute the Callable cb. The Thread is not started on construction, but when start() is called.


Member Function Documentation

void join (  ) 

Join() is called automatically in the destructor if not already called. Throws SystemError on failure

Reimplemented from Thread.

void terminate (  ) 

Forces the thread to terminate is dangerous and discouraged.

Reimplemented from Thread.

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6