- 01
 - 02
 - 03
 - 04
 - 05
 - 06
 - 07
 - 08
 - 09
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 - 39
 - 40
 - 41
 - 42
 - 43
 - 44
 - 45
 - 46
 - 47
 
typedef std::queue<Msg> Queue;    
    
struct SharedQueue
{
    private:
        Queue m_queue;
        boost::mutex m_mux;
        boost::condition_variable m_condvar;    
    private:
        struct is_empty
        {
            Queue& queue;
            is_empty( Queue& q):
                queue(q)
            {
            }
            bool operator()() const
            {
                return !queue.empty();
            }
        };
    public:
        void push(const Msg& msg)
        {
            boost::mutex::scoped_lock lock(m_mux);
            m_queue.push( msg);
            m_condvar.notify_one();
        }
        bool try_pop( Msg& msg, Kind kind)
        {
            boost::system_time const timeout=boost::get_system_time()+ boost::posix_time::milliseconds( 30000);
            boost::mutex::scoped_lock lock( m_mux);
            if ( m_condvar.timed_wait( lock, timeout, is_empty( m_queue)))
            {
                if( !m_queue.empty() && m_queue.front().kind == kind)
                {
                    msg = m_queue.front();
                    m_queue.pop();
                    return true;
                }
            }
            return false;
        }
};
                                    
 Follow us!