#ifndef _THREAD_H_
#define _THREAD_H_
#include <string>

#include "Event.h"
#include "Type.h"

namespace jf {

class Thread {
   public:
    Thread(std::string const& strName = "unNamed");

    virtual ~Thread();

    virtual bool start();
    virtual bool stop(unsigned uTimeout = INFINITE, bool bForce = true);
    bool signalled();
    bool active() const;
    Event& stop_event();

   protected:
    virtual U32 run() = 0;

   private:
    static void* threadproc(void* obj);
    std::string m_strName;
    pthread_t m_thread;
    Event m_stopEvent;    //调用者通知子线程退出
    Event m_stopedEvent;  //子线程通知调用者自己已经退出
};
}  // namespace jf

#endif  //_THREAD_H_
