首页 > 其他 > 详细

条件锁类

时间:2014-07-18 12:07:48      阅读:292      评论:0      收藏:0      [点我收藏+]
#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

条件锁类

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!