#ifndef MULTTHREAD_H #define MULTTHREAD_H // MultTHread.h -- Illustration of using the basic features of // ThreadSafeErrorLogger mechanism with multiple threads. // // This header for the example program is in two logical pieces: // // First we show the header for the framework code that would support // various phsyicists' modules. // // Second we show what would typically be in the header for the user code // written by physicists. // // This code is VERY similar to basicUsage.h // Look for // <------ *** to see the modifications due to using TS ErrorLog // Look for // <====== to see how the threads are set up; user code // may do this differently, of course. // ------------------------------------- // Headers for files making up Framework // ------------------------------------- // // Event.h // // This is a rather lame mock-up of what an Event looks like. // The framework will pass an Event from one module to the next. class Event { public: int data; inline Event( int d ) : data(d) { } }; // Event // --------------------- // // Module.h -- the base class for all physicist modules // // Normally this would include framework.h. // In this illustration that content is in this same file. #ifndef ZMENVIRONMENT_H #include "ZMutility/ZMenvironment.h" #endif #include #include "ErrorLogger/ThreadSafeErrorLog.h" // <------ *** struct Mutex { // <------ *** Mutex(); // <------ *** ~Mutex(); }; // <------ *** extern "C" {typedef void*(*cprog)(void*);} // <====== void * threadProgram (void *v); // <====== class Module { public: Module( const std::string & name ); virtual void operator()( Event & e ) = 0; // do this module's processing! virtual ~Module(); protected: // ThreadSafeErrorLog errlog; // <------ *** // // <====== // THIS IS A KEY POINT: // // The errlog is available to all methods of all classes // derived from Module. Since each thread will instantiate // its own set of Modules, each such set uses a distinct // ThreadSafeErrorLog. This is what keeps the error // messages from getting mixed up. // int threadNumber; }; // Module // ----------------------------- // Header for Physicsists' Code // ----------------------------- // // DoPhysics.h -- Many physicists can supply this sort of class // // Normally one would include framework.h. // In this illustration that content is in this same file. // The following are defined in that framework: // class Event; // class Module; // For all these examples, we suppose the physicist will provide code in // the form of a class with an operator() method taking an Event. // That is, the physicist provides a class (DoPhysics in this case) // rather than a global function. // Normally one would include but it is included above in this file. class DoPhysics : public Module { public: inline DoPhysics( const std::string & name, int tnum ) : Module(name) { threadNumber = tnum; } void operator()( Event & event ); // THIS IS WHERE ALL THE PHYSICS // CODE WILL GO. }; // DoPhysics #endif /* MULTTHREAD_H */