码迷,mamicode.com
首页 > 其他好文 > 详细

条件锁类

时间:2014-07-18 12:01:59      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   re   div   

#include <pthread.h>

    class CTestLock
    {
    public:
        CTestLock()        { pthread_mutex_init(&mutex_t_, NULL);  pthread_cond_init(&cond_t_, NULL);      }
        ~CTestLock()       { pthread_mutex_destroy(&mutex_t_);     pthread_cond_destroy(&cond_t_);          }
        int Lock()          { int nRetCode = pthread_mutex_lock(&mutex_t_);         return (nRetCode == 0); }
        int Unlock()      { int nRetCode = pthread_mutex_unlock(&mutex_t_);       return (nRetCode == 0); }
        int Wait()           { int nRetCode = pthread_cond_wait(&cond_t_,&mutex_t_); return (nRetCode == 0); }
        int Signal()       { int nRetCode = pthread_cond_signal(&cond_t_);          return (nRetCode == 0); }    
        int Broadcast()   { int nRetCode = pthread_cond_broadcast(&cond_t_);      return (nRetCode == 0); }
        
    private:
        pthread_mutex_t mutex_t_;
        pthread_cond_t cond_t_;
    };

条件锁类,布布扣,bubuko.com

条件锁类

标签:des   style   blog   color   re   div   

原文地址:http://www.cnblogs.com/youngt/p/3853058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!