c++ boost 线程级信号量


 1 class FS_Semaphora {
 2     private:
 3         unsigned int count;
 4         boost::condition_variable condition;
 5         boost::mutex lock;
 6 
 7     public:
 8         FS_Semaphora() {
 9             count = 0;
10         }
11 
12         FS_Semaphora(unsigned int cnt) : count(cnt) {
13 
14         }
15 
16         void post() {
17             lock.lock();
18             count++;
19             lock.unlock();
20             condition.notify_one();
21         }
22 
23         void wait() {
24             boost::unique_lock _lock(lock);
25             while (count == 0) {
26                 condition.wait(_lock);
27             }
28             count--;
29         }
30     };