Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62122
  • 博文数量: 18
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 281
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-20 13:06
文章分类

全部博文(18)

文章存档

2011年(1)

2009年(1)

2008年(16)

我的朋友

分类: C/C++

2009-01-13 17:21:04

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

}

}
阅读(952) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~