void CPrcThread::suspend()
{
ifdef WIN32
//do windows specific things here...
#endif
#ifdef __linux__
pthread_mutex_lock(&mutex);
flag--;
pthread_mutex_unlock(&mutex);
#endif
}
void CPrcThread::resume()
{
#ifdef WIN32
//do windows specific things here...
#endif
#ifdef __linux__
pthread_mutex_lock(&mutex);
flag++;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
#endif
}
void* CPrcThread::threadFunc(void* pParameter)
{
while(1)
{
#ifdef WIN32
//do windows specific things here...
//no member variables accessed here so its ok...
#endif
#ifdef __linux__
pthread_mutex_lock(&mutex);
while(flag <= 0)
{
pthread_cond_wait(&cond, &mutex);
}
pthread_mutex_unlock(&mutex);
#endif
//actual thread work here
}
}
阅读(1013) | 评论(0) | 转发(0) |