Is it true that C++0x will come without semaphores? There are already some questions on Stack Overflow regarding the use of semaphores. I use them (posix semaphores) all the
Based on Maxim Yegorushkin's answer, I tried to make the example in C++11 style.
#include
#include
class Semaphore {
public:
Semaphore (int count_ = 0)
: count(count_) {}
inline void notify()
{
std::unique_lock lock(mtx);
count++;
cv.notify_one();
}
inline void wait()
{
std::unique_lock lock(mtx);
while(count == 0){
cv.wait(lock);
}
count--;
}
private:
std::mutex mtx;
std::condition_variable cv;
int count;
};