Linux多线程编程工具库liblmp_tool github: https://github.com/Dwyane05/liblmp_tool
使用RAII手法封装
MutexLock& mutex_;
pthread_cond_t pcond_;
实现条件变量和互斥锁的使用;
头文件:
/*
* Use of this source code is governed by a BSD-style license
* that can be found in the License file.
*
* Condition.h
* Created on: May 30, 2019
* Author: cuiyongfei
*/
#ifndef LMP_TOOL_CONDITION_H
#define LMP_TOOL_CONDITION_H
#include "Mutex.h"
#include <pthread.h>
namespace lmp_tool
{
class Condition : noncopyable
{
public:
explicit Condition(MutexLock& mutex)
: mutex_(mutex)
{
MCHECK(pthread_cond_init(&pcond_, NULL));
}
~Condition()