Ai
1 Star 0 Fork 0

Shawy/2023Linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LockGuard.hpp 638 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shawy 提交于 2023-04-26 15:17 +08:00 . ThreadPool Test1
#pragma once
#include <iostream>
#include <pthread.h>
#include <string>
class Mutex
{
public:
Mutex(pthread_mutex_t* mtx)
: _pmtx(mtx)
{}
void lock()
{
pthread_mutex_lock(_pmtx);
}
void unlock()
{
pthread_mutex_unlock(_pmtx);
}
~Mutex()
{}
private:
pthread_mutex_t* _pmtx;
};
class LockGuard
{
public:
LockGuard(pthread_mutex_t* mtx)
: _mtx(mtx)
{
_mtx.lock();
//std::cout <<"---加锁---" << std::endl;
}
~LockGuard()
{
_mtx.unlock();
//std::cout << "---解锁---" << std::endl;
}
private:
Mutex _mtx;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/shawyxy/2023-linux.git
git@gitee.com:shawyxy/2023-linux.git
shawyxy
2023-linux
2023Linux
main

搜索帮助