00001 #ifndef Runnable_H 00002 #define Runnable_H 00003 00004 #include "Exceptions.h" 00005 #include <string> 00006 00007 BOREALIS_NAMESPACE_BEGIN; 00008 00009 // This class is not designed to gracefully handle concurrently multithreaded 00010 // access, so be careful. 00011 class Runnable 00012 { 00013 public: 00014 Runnable(); 00015 Runnable(const Runnable & rhs); 00016 virtual ~Runnable(); 00017 Runnable & operator=(const Runnable & rhs); 00018 00019 // Returns a pointer to the exception, if there is one, that was thrown by the 00020 // Runanble's 'run()' method's most recent execution in a PtThreadPool. 00021 00022 // The pointer is only valid until any of the following events: 00023 // (1) the next invocation of this class' 'deleteRunException()' method, or 00024 // (2) this Runnable is once again submitted for execution into a PtThreadPool, or 00025 // (3) this Runnable is deleted. 00026 exception *getRunException() const; 00027 00028 void deleteRunException(); // Invoking this will delete the current RunExcption from the 00029 // heap. Note: So will another invocation of 'cloneAndSetRunException(...)'. 00030 00031 // This method is invoked when this object is executed in a thread. 00032 virtual void run() throw() = 0; 00033 00034 void setRunException(exception *pException); 00035 00036 // Clones the specified exception onto the heap, and then makes that clone be 00037 // this Runnable's current RunException. 00038 void cloneAndSetRunException(const std::exception &e); 00039 00040 private: 00041 00042 exception *_lastRunException; 00043 }; 00044 00045 BOREALIS_NAMESPACE_END; 00046 00047 #endif