Skip to content
Snippets Groups Projects
Select Git revision
  • 0d1ed08a8cac117a423f0bc5ab64decd61094f1b
  • main default protected
  • upgrade-cpp
  • release_2_0_3
  • release_2_0_2
  • release_2_0_1
  • release_2_0_0
  • release_1_0_5
  • release_1_0_4
  • release_1_0_3
  • release_1_0_2
  • release_1_0_1
  • release_1_0_0
  • operational_1_2_0
  • operational_1_1_1
  • operational_1_1_0
  • operational_1_0_0
  • v0
  • initial_version
19 results

TangoThread.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    TangoThread.h 26.61 KiB
    
    #ifndef _TangoThread_
    #define _TangoThread_
    
    
    #include <tango.h>
    #include <omnithread.h>
    #include <iostream>
    
    namespace Tango
    {
    
    /**
    * mutex
    */
    //class Mutex : private omni_mutex
    class Mutex : public omni_mutex
    {
    public:
      Mutex(void)
        :omni_mutex()
      {};
      
      ~Mutex(void){}
      /**
      * lock mutex
      */
      void lock(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_mutex::lock();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Mutex::lock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot lock mutex"),
            (const char*)("Mutex::lock")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Mutex::unlock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot lock mutex"),
            (const char*)("Mutex::lock")
            );      
        }catch(...)
        {
          cout<<"===exception Mutex::lock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot lock mutex"),
            (const char*)("Mutex::lock"));
        }
      }
      /**
      * unlock mutex
      */
      void unlock(void)
        throw (Tango::DevFailed)
      { 
        try{
          omni_mutex::unlock();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Mutex::unlock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot unlock mutex"),
            (const char*)("Mutex::unlock")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Mutex::unlock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot unlock mutex"),
            (const char*)("Mutex::unlock")
            );      
        }catch(...)
        {
          cout<<"===exception Mutex::unlock==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot unlock mutex"),
            (const char*)("Mutex::unlock"));
        }
      }
      
    private:
      /**
      * Dummy copy ctor to prevent copying
      */
      Mutex(const Mutex&);
      /**
      * Dummy operator = to prevent copying
      */
      Mutex& operator=(const Mutex&);
    };
      
    /**
    * mutex lock. To use a single instance of Mutex. \n
    * example: \n
    * { \n
    * MutexLock ml(mutex); //lock \n
    * ... \n
    * } //unlock \n
    */
    class MutexLock
    {
      Mutex& mutex_;
    public:
      /**
      * Ctor. lock a mutex
      * @param _mutex The mutex to lock.
      */
      MutexLock(Mutex& _mutex)
        :mutex_(_mutex)
      {mutex_.lock();}
      /**
      * Dtor. Unlock mutex locked in ctor.
      */
      ~MutexLock(void)
      {mutex_.unlock();}
    private:
      /**
      * Dummy copy ctor to prevent copying
      */
      MutexLock(const MutexLock&);
      /**
      * Dummy operator = to prevent copying
      */
      MutexLock& operator=(const MutexLock&);
    };
    
    /**
    * condition
    */
    //class Condition: private omni_condition
    class Condition: public omni_condition
    {
    public:
      /**
      * Ctor.
      * @param _mutex A pointer to an existing mutex.
      * There is an implicit lock and unlock around wait() and timedwait()
      */
      Condition(Tango::Mutex* _mutex)
        :omni_condition((omni_mutex*)_mutex)
      {}
      
      ~Condition(void){}
      /**
      * Wait for the condition variable to be signalled.
      * The mutex is implicitly released before waiting and locked again after waking up.
      * If wait() is called by multiple threads, a signal may wake up more than one thread. \n
      * See POSIX threads documentation for details.
      */
      void wait(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_condition::wait();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Condition::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot wait condition"),
            (const char*)("Condition::wait")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Condition::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot wait condition"),
            (const char*)("Condition::wait")
            );      
        }catch(...)
        {
          cout<<"===exception Condition::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot wait condition"),
            (const char*)("Condition::wait"));
        }
      }
      /**
      * @param secs The time in seconds to wait (in absolute time).
      * @param nanosecs The time in nanoseconds to wait (in absolute time).
      * @see Tango::Thread::get_time() to wait for a relative time from now.
      * @return 1 if sucessfully signalled, 0 if time expired.
      */
      int timedwait(unsigned long secs, unsigned long nanosecs = 0)
        throw (Tango::DevFailed)
      {
        int r ;
        try{
          r = omni_condition::timedwait(secs, nanosecs);
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Condition::timedwait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot timedwait condition"),
            (const char*)("Condition::timedwait")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Condition::timedwait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot timedwait condition"),
            (const char*)("Condition::timedwait")
            );      
        }catch(...)
        {
          cout<<"===exception Condition::timedwait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot timedwait condition"),
            (const char*)("Condition::timedwait"));
        }
        return r;
      }
      /**
      * If one or more threads have called wait(), signal wakes up at least one of them, possibly more.\n
      * See POSIX threads documentation for details.
      */
      void signal(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_condition::signal();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Condition::signal==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot signal condition"),
            (const char*)("Condition::signal")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Condition::signal==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot signal condition"),
            (const char*)("Condition::signal")
            );      
        }catch(...)
        {
          cout<<"===exception Condition::signal==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot signal condition"),
            (const char*)("Condition::signal"));
        }
      }
      /**
      * broadcast is like signal() but wakes all threads which have called wait()
      */
      void broadcast(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_condition::broadcast();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Condition::broadcast==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot broadcast condition"),
            (const char*)("Condition::broadcast")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Condition::broadcast==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot broadcast condition"),
            (const char*)("Condition::broadcast")
            );      
        }catch(...)
        {
          cout<<"===exception Condition::broadcast==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot broadcast condition"),
            (const char*)("Condition::broadcast"));
        }
      }
    private:
      /**
      * Dummy copy ctor to prevent copying
      */
      Condition(const Condition&);
      /**
      * Dummy operator = to prevent copying
      */
      Condition& operator=(const Condition&);
    };
    
    
    /**
    * Counting semaphore
    */
    class Semaphore : private omni_semaphore
    {
    public:
      /**
      * Ctor.
      * @param initial_value The value from which to start to increment with wait() (or trywait()) or decremenent with post().
      */
      Semaphore(unsigned int initial_value = 1)
        :omni_semaphore(initial_value)
      {}
      ~Semaphore(void){}
      /**
      * If semaphore value is > 0 then decrement it and carry on. If it's 0 then block.
      */
      void wait(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_semaphore::wait();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Semaphore::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot wait semaphore"),
            (const char*)("Semaphore::wait")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Semaphore::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot wait semaphore"),
            (const char*)("Semaphore::wait")
            );      
        }catch(...)
        {
          cout<<"===exception Semaphore::wait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot wait semaphore"),
            (const char*)("Semaphore::wait"));
        }
      }
      /**
      * If semaphore value is > 0 then decrement it and carry on. If it's already 0 then return 0.
      */
      int trywait(void)
        throw (Tango::DevFailed)
      {
        int r;
        try{
          r= omni_semaphore::trywait();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Semaphore::trywait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot trywait semaphore"),
            (const char*)("Semaphore::trywait")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Semaphore::trywait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot trywait semaphore"),
            (const char*)("Semaphore::trywait")
            );      
        }catch(...)
        {
          cout<<"===exception Semaphore::trywait==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot trywait semaphore"),
            (const char*)("Semaphore::trywait"));
        }
        return r;
      }
      /**
      * If any threads are blocked in wait(), wake one of them up. 
      * Otherwise increment the value of the semaphore.
      */
      void post(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_semaphore::post();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Semaphore::post==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot post semaphore"),
            (const char*)("Semaphore::post")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Semaphore::post==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot post semaphore"),
            (const char*)("Semaphore::post")
            );      
        }catch(...)
        {
          cout<<"===exception Semaphore::post==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot post semaphore"),
            (const char*)("Semaphore::post"));
        }
      }
    
    private:
      /**
      * Dummy copy ctor to prevent copying
      */
      Semaphore(const Semaphore&);
      /**
      * Dummy operator = to prevent copying
      */
      Semaphore& operator=(const Semaphore&); 
    };
    
    /**
    * semaphore lock. To use a single instance of Semaphore. \n
    * example: \n
    * { \n
    * SemaphoreLock ml(sem); //wait \n
    * ... \n
    * } //post \n
    */
    /**
    * semaphore lock
    */
    class SemaphoreLock
    {
      Semaphore& sem;
    public:
      /**
      * 
      */
      SemaphoreLock(Semaphore& s):sem(s){sem.wait();}
      /**
      * 
      */
      ~SemaphoreLock(void){sem.post();}
    private:
      /**
      * Dummy copy ctor to prevent copying
      */
      SemaphoreLock(const SemaphoreLock&);
      /**
      * Dummy operator = to prevent copying
      */
      SemaphoreLock& operator=(const SemaphoreLock&); 
    };
    
    
    /**
    * thread
    */
    class Thread : private omni_thread
    {
    
    public:
      /**
      * Priority of the thread.
      */
      enum thread_priority
      {
        LOW = omni_thread::PRIORITY_LOW,
        NORMAL = omni_thread::PRIORITY_NORMAL,
        HIGH = omni_thread::PRIORITY_HIGH
      };
      /**
      * State of the thread
      */
      enum thread_state
      {
        NEW = omni_thread::STATE_NEW,
          RUNNING = omni_thread::STATE_RUNNING,
          TERMINATED = omni_thread::STATE_TERMINATED
      };
      /**
      * Ctor of a detached thread running the given function.
      * @param fn The function to run.
      * @param arg The input argument of the given function.
      * @param pri The priority of the thread.
      */
      Thread(void (*fn)(void*), void* arg = NULL, thread_priority pri = NORMAL)
        :omni_thread(fn, arg, (omni_thread::priority_t)pri)
      {}
      /**
      * Ctor of an undetached thread running the given function (can have a return value).
      * @param fn The function to run.
      * @param arg The input argument of the given function.
      * @param pri The priority of the thread.
      */
       Thread(void* (*fn)(void*), void* arg = NULL, thread_priority pri = NORMAL)
        :omni_thread(fn, arg, (omni_thread::priority_t)pri)
      {}
      /**
      * Ctor of a thread thread that will run either run() or run_undetached()
      * @param arg The input argument of run() or run_undetached()
      * @param pri The priority of the thread
      */
      Thread(void* arg=NULL, thread_priority pri = NORMAL)
        :omni_thread(arg, (omni_thread::priority_t)pri)
      {}
      /**
      * Call run() or the given function (depends on ctor called).
      */
      void start(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::start();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::start==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot start thread"),
            (const char*)("Thread::start")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::start==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot start thread"),
            (const char*)("Thread::start")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::start==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot start thread"),
            (const char*)("Thread::start"));
        }
      }
      /**
      * Causes the calling thread waiting for the completion of this thread.
      * @param arg The value returned by the method called with start() or start_undetached().
      * Only undetached threads can be joined.
      */
      void join(void** arg)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::join(arg);
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::join==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot join thread"),
            (const char*)("Thread::join")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::join==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot join thread"),
            (const char*)("Thread::join")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::join==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot join thread"),
            (const char*)("Thread::join"));
        }
      }
      /**
      * Set the priority of the thread.
      */
      void set_priority(thread_priority prio) 
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::set_priority((omni_thread::priority_t)prio); 
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::set_priority==="<<endl;
          Tango::Except::throw_exception(
          (const char*)("THREAD_FATAL_ERROR"),
          (const char*)("Cannot set priority "),
          (const char*)("Thread::set_priority")
          );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::set_priority==="<<endl;
          Tango::Except::throw_exception(
          (const char*)("THREAD_INVALID_ERROR"),
          (const char*)("Cannot set priority"),
          (const char*)("Thread::set_priority")
          );      
        }catch(...)
        {
          cout<<"===exception Thread::set_priority==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot set priority"),
            (const char*)("Thread::set_priority"));
        }
      }
      /**
      * Causes the calling thread to terminate.
      */
      static void exit(void* return_value = NULL)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::exit(return_value);
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::exit==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot exit "),
            (const char*)("Thread::exit")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::exit==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot exit"),
            (const char*)("Thread::exit")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::exit==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot exit"),
            (const char*)("Thread::exit"));
        }
        
      }
      /**
      * allow another thread to run.
      */
      static void yield(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::yield();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::yield==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot yield "),
            (const char*)("Thread::yield")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::yield==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot yield"),
            (const char*)("Thread::yield")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::yield==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot yield"),
            (const char*)("Thread::yield"));
        }
      }
      /**
      * Sleep for the time specified.
      */
      static void sleep(unsigned long secs, unsigned long nanosecs = 0)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::sleep(secs, nanosecs);
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::sleep==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot sleep "),
            (const char*)("Thread::sleep")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::sleep==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot sleep"),
            (const char*)("Thread::sleep")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::sleep==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot sleep"),
            (const char*)("Thread::sleep"));
        }
      }
      /**
      * Calculate an absolute time in seconds and nanoseconds, for using Condition::timedwait()
      * @param rel_sec The desired relative time (seconds part). 
      * @param rel_nsec The desired relative time (nanoseconds part). 
      * @param abs_sec The absolute time returned (seconds part). 
      * @param abs_nsec The absolute time returned (nanoseconds part). 
      */
      static void get_time(unsigned long* abs_sec, unsigned long* abs_nsec,
        unsigned long rel_sec = 0, unsigned long rel_nsec=0)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::get_time(abs_sec, abs_nsec, rel_sec, rel_nsec);
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::get_time==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot get time "),
            (const char*)("Thread::get_time")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::get_time==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot get time"),
            (const char*)("Thread::get_time")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::get_time==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get time"),
            (const char*)("Thread::get_time"));
        }
      }
      /**
      * Set the size of the stack.
      */
      static void stacksize(unsigned long sz)
        throw (Tango::DevFailed)
      { 
        try{ 
          omni_thread::stacksize(sz); 
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot set stacksize "),
            (const char*)("Thread::stacksize")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot set stacksize"),
            (const char*)("Thread::stacksize")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot set stacksize"),
            (const char*)("Thread::stacksize"));
        }
      }
       /**
      * Get the size of the stack.
      */
      static unsigned long stacksize()
        throw (Tango::DevFailed)
      { 
        try{ 
          return omni_thread::stacksize();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot get stacksize "),
            (const char*)("Thread::stacksize")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot get stacksize"),
            (const char*)("Thread::stacksize")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::stacksize==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get stacksize"),
            (const char*)("Thread::stacksize"));
        }
      }
      
      /**
      * Get the priority of the thread.
      */
      thread_priority priority(void)
        throw (Tango::DevFailed)
      { 
        try{ 
          return (thread_priority)omni_thread::priority();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::priority==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot get priority "),
            (const char*)("Thread::priority")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::priority==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot get priority"),
            (const char*)("Thread::priority")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::priority==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get priority"),
            (const char*)("Thread::priority"));
        }
      }
      
      /**
      * Get the current state of the thread
      */
      thread_state state(void)
        throw (Tango::DevFailed)
      { 
        try{ 
          return (thread_state)omni_thread::state();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::state==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot get state "),
            (const char*)("Thread::state")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::state==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot get state"),
            (const char*)("Thread::state")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::state==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get state"),
            (const char*)("Thread::state"));
        }
      }
    
      
      /**
      * @return The id of the thread
      */
      int id(void)
        throw (Tango::DevFailed)
      { 
        try{ 
          return omni_thread::id();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::id==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot get id "),
            (const char*)("Thread::id")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::id==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot get id"),
            (const char*)("Thread::id")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::id==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get id"),
            (const char*)("Thread::id"));
        }
      }
      /**
      * Will run the member function run_undetached()
      */
      void  start_undetached(void)
        throw (Tango::DevFailed)
      {
        try{
          omni_thread::start_undetached();
        }catch(omni_thread_fatal)
        {
          cout<<"===exception Thread::start_undetached==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_FATAL_ERROR"),
            (const char*)("Cannot start_undetached thread"),
            (const char*)("Thread::start_undetached")
            );
        }catch(omni_thread_invalid)
        {
          cout<<"===exception Thread::start undetached==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("THREAD_INVALID_ERROR"),
            (const char*)("Cannot start undetached thread"),
            (const char*)("Thread::start_undetached")
            );      
        }catch(...)
        {
          cout<<"===exception Thread::id==="<<endl;
          Tango::Except::throw_exception(
            (const char*)("UNKNOWN_ERROR"),
            (const char*)("Cannot get start undetached thread"),
            (const char*)("Thread::start_undetached"));
        }
      }
    protected:
      virtual ~Thread(void){}
    private:
      /**
      * When construct with Thread(void* arg=NULL, thread_priority pri = NORMAL), this function is called by start()
      */
      virtual void run(void* arg){}
      /**
      * When construct with Thread(void* arg=NULL, thread_priority pri = NORMAL), this function is called by start_undetached()
      */
      virtual void* run_undetached(void* arg){return NULL;}
    
      
      Thread(const Thread&);
      Thread& operator=(const Thread&);
    
    };
    
    }
    
    #endif //_TangoThread_