C++互拆锁
来源:互联网 发布:淘宝怎么给子账号授权 编辑:程序博客网 时间:2024/06/05 20:30
CLock.h
#ifndef __CLOCK_H__#define __CLOCK_H__#include <pthread.h>class ILock {public:virtual ~ILock() {};virtual void Lock() const = 0;virtual void UnLock() const = 0;};class CMutex : public ILock {public:CMutex();~CMutex();virtual void Lock() const;virtual void UnLock() const;private:mutable pthread_mutex_t m_mutex;};class CMyLock {public:CMyLock(const ILock&);~CMyLock();private:const ILock& m_lock;};#endif
CLock.cpp
#include "CLock.h"CMutex::CMutex() {pthread_mutex_init(&m_mutex, NULL);}CMutex::~CMutex() {pthread_mutex_destroy(&m_mutex);}void CMutex::Lock() const {pthread_mutex_lock(&m_mutex);}void CMutex::UnLock() const{pthread_mutex_unlock(&m_mutex);}CMyLock::CMyLock(const ILock& m): m_lock(m){m_lock.Lock();}CMyLock::~CMyLock() {m_lock.UnLock();}
阅读全文
1 0
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- 文件系统读写--文件预读 和 文件锁
- scrapy 官方文档(入门必备)
- 运维之思科篇 -----6.思科项目练习
- Guest is not running ---KVM
- Cloudera迁移scm数据库
- C++互拆锁
- 冗余计算机项目的调试问题归纳
- 怎么开始并且争取做一个优秀的计算机视觉研究人员
- 递归算法
- java.lang.IllegalStateException:Cannot add header view to list==setAdapter has already been called.
- SQL2008 提示评估期已过的解决方法
- Ubuntu 16.04开机蓝屏
- 设计模式(二)单例模式(转)
- 2017.10.12 Dockerfile ENV命令详解