15 Star 25 Fork 3

eclipser / thread

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Thread.cpp 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2014-01-17 17:45 . 事例5
#include "Thread.h"
#include "Common.h"
#include "Lock.h"
uint g_QuitThreadCount = 0;
MyLock g_thread_lock;
Thread::Thread() {
m_TID = 0;
m_Status = Thread::READY;
}
Thread::~Thread() {
}
void Thread::start() {
__ENTER_FUNCTION
if (m_Status != Thread::READY)
return;
pthread_create(&m_TID, NULL, ThreadProcess, this);
__LEAVE_FUNCTION
}
void Thread::stop() {
}
void Thread::exit(void* retval) {
try {
pthread_exit(retval);
} catch (...) {
}
}
void Thread::run() {
}
//------------------------------------------------------------------------------
void* ThreadProcess(void* derivedThread) {
__ENTER_FUNCTION
Thread* thread = (Thread*) derivedThread;
if (thread == NULL)
return NULL;
// set thread's status to "RUNNING"
thread->setStatus(Thread::RUNNING);
// here - polymorphism used. (derived::run() called.)
thread->run();
// set thread's status to "EXIT"
thread->setStatus(Thread::EXIT);
//INT ret = 0;
//thread->exit(&ret);
g_thread_lock.Lock();
g_QuitThreadCount++;
g_thread_lock.Unlock();
__LEAVE_FUNCTION
return NULL; // avoid compiler's warning
}
C++
1
https://gitee.com/eclipser/thread.git
git@gitee.com:eclipser/thread.git
eclipser
thread
thread
master

搜索帮助