示例#1
0
void consumer(
    the_ostream &mos,
    boost::sync_queue<int> & sbq)
{
  using namespace boost;
  try {
    for(int i=0; ;++i)
    {
      int r;
      sbq.pull_front(r);
      //sbq >> r;
      mos << i << " pull(" << r << ") "<< sbq.size()<<"\n";

      this_thread::sleep_for(chrono::milliseconds(250));
    }
  }
  catch(sync_queue_is_closed&)
  {
    mos << "closed !!!\n";
  }
  catch(...)
  {
    mos << "exception !!!\n";
  }
}
示例#2
0
void producer(the_ostream &mos, boost::sync_queue<int> & sbq)
{
  using namespace boost;
  try {
    for(int i=0; ;++i)
    {
      sbq.push_back(i);
      //sbq << i;
      mos << "push_back(" << i << ") "<< sbq.size()<<"\n";
      this_thread::sleep_for(chrono::milliseconds(200));
    }
  }
  catch(sync_queue_is_closed&)
  {
    mos << "closed !!!\n";
  }
  catch(...)
  {
    mos << "exception !!!\n";
  }
}
示例#3
0
void consumer3(the_ostream &mos, boost::sync_queue<int> & sbq)
{
  using namespace boost;
  try {
    for(int i=0; ;++i)
    {
      int r;
      queue_op_status res = sbq.wait_pull_front(r);
      if (res==queue_op_status::closed) break;
      mos << i << " wait_pull_front(" << r << ")\n";
      this_thread::sleep_for(chrono::milliseconds(250));
    }
  }
  catch(...)
  {
    mos << "exception !!!\n";
  }
}
示例#4
0
void consumer2(the_ostream &mos, boost::sync_queue<int> & sbq)
{
  using namespace boost;
  try {
    for(int i=0; ;++i)
    {
      int r;
      queue_op_status st = sbq.try_pull_front(r);
      if (queue_op_status::closed == st) break;
      if (queue_op_status::success == st) {
        mos << i << " pull(" << r << ")\n";
      }
      this_thread::sleep_for(chrono::milliseconds(250));
    }
  }
  catch(...)
  {
    mos << "exception !!!\n";
  }
}
示例#5
0
 boost::queue_op_status operator()(ValueType& v)
 {
   go_->wait();
   return q_->wait_pull(v);
 }
示例#6
0
 ValueType operator()()
 {
   go_->count_down_and_wait();
   return q_->pull();
 }
示例#7
0
 void operator()()
 {
   go_->count_down_and_wait();
   q_->push(42);
 }