Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BOOST_THREAD_BINARY_SEMAPHORE
- #define BOOST_THREAD_BINARY_SEMAPHORE
- #include <boost/thread/condition.hpp>
- #include <boost/thread/mutex.hpp>
- class binary_semaphore
- {
- typedef boost::mutex::scoped_lock lock;
- public:
- explicit binary_semaphore( bool initial_set = false )
- : _set( initial_set )
- {}
- void signal()
- {
- lock lk( _mutex );
- _set = true;
- _condition.notify_one();
- }
- void wait()
- {
- lock lk( _mutex );
- while( _set == false )
- {
- _condition.wait( lk );
- }
- _set = false ;
- }
- private:
- bool _set;
- boost::mutex _mutex;
- boost::condition_variable _condition;
- };
- #endif // BOOST_THREAD_BINARY_SEMAPHORE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement