boost 轻量级信号量
睿丰德科技 专注RFID识别技术和条码识别技术与管理软件的集成项目。质量追溯系统、MES系统、金蝶与条码系统对接、用友与条码系统对接
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread.hpp>
class semaphore
{
unsigned int count_;
boost::mutex mutex_;
boost::condition_variable condition_;
public:
explicit semaphore(unsigned int initial) : count_(initial){}
void signal()
{
{
boost::lock_guard<boost::mutex> lock(mutex_);
++count_;
}
condition_.notify_one();
}
void wait()
{
boost::unique_lock<boost::mutex> lock(mutex_);
while (count_ == 0)
{
condition_.wait(lock);
}
--count_;
}
};
RFID管理系统集成商 RFID中间件 条码系统中间层 物联网软件集成