Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MynahSA::Thread< T > Class Template Reference

#include <thread.hpp>

List of all members.

Public Member Functions

 Thread (const T &startclass)
 Cosntructor - pass in a functional object.
 ~Thread ()
void * join ()


Detailed Description

template<class T>
class MynahSA::Thread< T >

Class thread implements a thread object. The template typename must specify a functor object.

The functor object must support copy construction: The Thread class copies the object to a heap allocated object, then spawns a thread on it. This allows the original object to go out of scope without causing segmentation faults.

The copied object is deleted when the thread exists.

Once a Thread instance is created an operating system thread is created and the operator() method of the provided class reference is invoked.

Parameters are not passable to the thread using the construction mechanism - rather instead, all parameters should be passed in using the functor's constructor.

Threads may be joined using the join method. Calling join on a thread from the parent thread will cause the parent thread to block until the child has terminated.

Note: Class Thread is unavailable when MYNAHSA_USE_BOOST is set as a compile time option.

Bug:
no handling of thread limits yet.

no handling of potential failures in thread creation.

Definition at line 145 of file thread.hpp.


Constructor & Destructor Documentation

template<class T>
MynahSA::Thread< T >::~Thread  )  [inline]
 

Destructor: In the event of the thread being thrown away, we detach, allowing memory to be recovered on thread termination.

Definition at line 168 of file thread.hpp.

00168               { 
00169 #ifndef WIN32
00170       pthread_detach(_thread);
00171 #endif
00172     }    


Member Function Documentation

template<class T>
void* MynahSA::Thread< T >::join  )  [inline]
 

Join a thread. On Win32 will return 0 by default. On unix will return whatever the called thread returned.

Definition at line 176 of file thread.hpp.

00176                  { 
00177 #ifdef WIN32
00178       WaitForSingleObject( _hThread, INFINITE );
00179       return 0;
00180 #else
00181       void* vrtn;
00182       pthread_join(_thread,&vrtn);
00183       return vrtn;
00184 #endif
00185     }


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