CMS 3D CMS Logo

Thread Class Reference

a self starting Thread Object More...

#include <Utilities/Threads/interface/Thread.h>

Inheritance diagram for Thread:

TSqueueConsumer< X, C >

List of all members.

Public Member Functions

 Thread ()
 constructor (in main thread)
unsigned int tid () const
virtual ~Thread ()
 destructor (in main thread)

Static Public Member Functions

static unsigned int self_tid ()
static void verboseOff ()
static void verboseOn ()

Public Attributes

std::ostream cout
 ostream

Protected Member Functions

void finalize ()
void initialize ()

Private Member Functions

virtual void abort ()=0
 called if exception trapped;
void operator() ()
 the thread main.
virtual void run ()=0
 body (in its own thread)
virtual void terminate ()=0
 called if Terminate trapped

Private Attributes

boost::threadt1
unsigned int tid_

Static Private Attributes

static bool verbose = false

Friends

struct Me

Classes

struct  Me
struct  Terminate
 thrown to terminate thread More...


Detailed Description

a self starting Thread Object

Definition at line 11 of file Thread.h.


Constructor & Destructor Documentation

Thread::Thread (  ) 

constructor (in main thread)

Definition at line 27 of file Thread.cc.

00027 : t1(0), cout(std::cout.rdbuf()){}

Thread::~Thread (  )  [virtual]

destructor (in main thread)

Definition at line 34 of file Thread.cc.

References GeneralUtilities::cout, lat::endl(), t1, and tid().

00034                {
00035   if (t1)
00036     GeneralUtilities::cout << " thread  " << tid() << "still active??? "  << std::endl;
00037   delete t1; t1=0;
00038 }


Member Function Documentation

virtual void Thread::abort (  )  [private, pure virtual]

called if exception trapped;

Implemented in TSqueueConsumer< X, C >.

Referenced by operator()().

void Thread::finalize ( void   )  [protected]

Definition at line 40 of file Thread.cc.

References GeneralUtilities::cout, lat::endl(), t1, tid(), and verbose.

Referenced by TSqueueConsumer< X, C >::~TSqueueConsumer().

00040                       {
00041   if (Thread::verbose) GeneralUtilities::cout << "wait for thread " << tid() << std::endl;
00042   (*t1).join();
00043   delete t1; t1=0;
00044 }

void Thread::initialize ( void   )  [protected]

Definition at line 29 of file Thread.cc.

References me, t1, and thread.

Referenced by TSqueueConsumer< X, C >::TSqueueConsumer().

00029                         {
00030   Me me(*this);
00031   t1 = new boost::thread(me);
00032 }

void Thread::operator() ( void   )  [private]

the thread main.

Definition at line 46 of file Thread.cc.

References abort(), className(), GeneralUtilities::cout, cout, Genexception::dump(), lat::endl(), run(), self_tid(), terminate(), tid_, and CMSexception::what().

00046                         {
00047   tid_ = self_tid();
00048   if (verbose) 
00049     GeneralUtilities::cout << " thread starts.." << self_tid() << std::endl;
00050   
00051   try{
00052 #ifdef __linux__
00053       LinuxElapsedTime lt(string("in Thread ")+toa()(tid_));
00054 #endif
00055       run();
00056   }
00057   catch ( Terminate ) {
00058     if (verbose)
00059       GeneralUtilities::cout << "thread " 
00060            << self_tid() << " terminates " << std::endl;
00061     terminate();
00062   }
00063   catch ( GenTerminate & cexp ) {
00064     GeneralUtilities::cout << "thread " 
00065          << self_tid() << " termination triggered by " << std::endl;
00066     cexp.dump(cout,true);
00067     terminate();
00068   }
00069   catch ( CMSexception & cexp) {
00070     GeneralUtilities::cout << "thread " 
00071          << self_tid() << " caught  CMS exception (" 
00072          << className(cexp) 
00073          << ") :" << endl;
00074     GeneralUtilities::cout << cexp.what() << std::endl;
00075     GeneralUtilities::cout << " inform producer...." << std::endl;
00076     UncatchedException uce;
00077     assert(&uce != 0); // Avoids warning message for unused variable uce.
00078     abort();
00079   }
00080   catch (...) {
00081     GeneralUtilities::cout << "thread " 
00082          << self_tid() << " caught unknown exception " << std::endl;    
00083     GeneralUtilities::cout << " inform producer...." << std::endl;
00084     UncatchedException uce;
00085     assert(&uce != 0); // Avoids warning message for unused variable uce.
00086     abort();
00087   }
00088   
00089 }

virtual void Thread::run (  )  [private, pure virtual]

body (in its own thread)

Implemented in TSqueueConsumer< X, C >.

Referenced by operator()().

unsigned int Thread::self_tid (  )  [static]

Definition at line 25 of file Thread.cc.

Referenced by operator()(), and TSqueueConsumer< X, C >::run().

00025 { return pthread_self();}

virtual void Thread::terminate (  )  [private, pure virtual]

called if Terminate trapped

Implemented in TSqueueConsumer< X, C >.

Referenced by operator()().

unsigned int Thread::tid (  )  const [inline]

Definition at line 21 of file Thread.h.

References tid_.

Referenced by finalize(), and ~Thread().

00021 { return tid_;}

void Thread::verboseOff (  )  [static]

Definition at line 22 of file Thread.cc.

00022 { verbose=false;}

void Thread::verboseOn (  )  [static]

Definition at line 20 of file Thread.cc.

00020 { verbose=true;}


Friends And Related Function Documentation

friend struct Me [friend]

Definition at line 46 of file Thread.h.


Member Data Documentation

std::ostream Thread::cout

ostream

Definition at line 51 of file Thread.h.

Referenced by operator()().

boost::thread* Thread::t1 [private]

Definition at line 24 of file Thread.h.

Referenced by finalize(), initialize(), and ~Thread().

unsigned int Thread::tid_ [private]

Definition at line 25 of file Thread.h.

Referenced by operator()(), and tid().

bool Thread::verbose = false [static, private]

Definition at line 37 of file Thread.h.

Referenced by finalize().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:33:27 2009 for CMSSW by  doxygen 1.5.4