1 Star 0 Fork 0

Miun11/Linux_learning

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Cond.hpp 792 Bytes
一键复制 编辑 原始数据 按行查看 历史
Miun11 提交于 2026-05-09 16:50 +08:00 . 条件变量封装
#include <iostream>
#include <unistd.h>
#include <pthread.h>
namespace CondModlue
{
class Cond
{
public:
Cond()
{
int n = pthread_cond_init(&_cond, nullptr);
(void)n;
}
// 让线程进入条件变量对应的等待队列
void Wait(pthread_mutex_t* mutex)
{
pthread_cond_wait(&_cond, mutex);
}
// 从等待队列唤醒一个线程
void Signal()
{
pthread_cond_signal(&_cond);
}
// 唤醒所有线程
void Broadcast()
{
pthread_cond_broadcast(&_cond);
}
~Cond()
{
pthread_cond_destroy(&_cond);
}
private:
pthread_cond_t _cond;
};
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/miun11/Linux_learning.git
git@gitee.com:miun11/Linux_learning.git
miun11
Linux_learning
Linux_learning
master

搜索帮助