circular_buf.size(); --buffered; buffer_not_full.notify_one(); return i; } private: int begin, end, buffered; std::vector<int> circular_buf; boost::condition buffer_not_full, buffer_not_empty; boost::mutex monitor; }; This embodies a technique called a monitor , which describes functions as “belonging to” the same monitor and ensures that only one function in that set can be executing at a time.