标签:
#include <mutex> #include <condition_variable> using namespace std; class semaphore{ private: mutex mtx; condition_variable cv; int count; public: semaphore(int count_ = 0):count(count_){;} void notify() { unique_lock<mutex> lck(mtx); ++count; cv.notify_one(); } void wait() { unique_lock<mutex> lck(mtx); while(count == 0){ cv.wait(lck); } count--; } };
Semaphore built from mutex in C++11
标签:
原文地址:http://www.cnblogs.com/Kai-Xing/p/4312999.html