Example #1
0
            blocking_job takeJob() throw(QueueBreak)
            {
                MutexGuard lock(&mutex_);
                
                while(queue_.size()==0 && running_)
                {
                    cond_.wait(mutex_);//release mutex and block here
                }
                //printf("thread wake: %s %d, and should do some job assignment here:%d\n",
                //Thread::ThreadName().c_str(), Thread::GetTid(), count);
                if(!running_)
                {
                    throw QueueBreak("QueueBreak");
                }

                blocking_job job = 0;
                if(queue_.size())
                {
                    job = queue_.front();
                    queue_.pop_front();
                }

                if(queue_.size())
                    cond_.notify();

                return job;
            }
 void start_thread() {
   thread_group thrgrp; 
   for (size_t i = 0;i < 4; ++i) {
     thrgrp.launch(boost::bind(
                           &simple_engine_test::thread,
                           this, i));
   }
   
   thrgrp.join();
   ASSERT_EQ(queue.size(), 0);
 }