线程启动问题
namespace THREAD
{
class CThread_RUN
{
public:
virtual void run()=0;
virtual void set_cache(hash_record* m_cache)=0;
virtual void set_log(LOG_SYSTEM::Log_system* log)=0;
};
class CThread
{
public:
CThread():m_cache(HASH_BASE){}
CThread(LOG_SYSTEM::Log_system* log):m_log(log){}
void start(CThread_RUN* arg);
hash_record* get_record();
void set_log(LOG_SYSTEM::Log_system* log);
private:
pthread_t m_tid;
hash_record m_cache;
LOG_SYSTEM::Log_system* m_log;
static void* thread_func(void* obj);
};
}
namespace THREAD
{
void CThread::start(CThread_RUN* arg)
{
arg->set_log(m_log);
arg->set_cache(&m_cache);
pthread_create(&m_tid,NULL,thread_func,(void*)arg);
}
hash_record* CThread::get_record()
{
return &m_cache;
}
void CThread::set_log(LOG_SYSTEM::Log_system* log)
{
m_log=log;
}
void* CThread::thread_func(void* obj)
{
pthread_detach(pthread_self());
CThread_RUN* obj1=(CThread_RUN*)obj;
obj1->run();
}
}
- thread thread_run关系图
![Alt text](./屏幕快照 2015-04-10 下午3.42.26.png)
缓存和日志系统对象指针传参问题