Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-13 14:10:46


> Yep, one queue per thread. Just like the original example - one CV per
> thread - unless I misinterpreted it.

how about one mutex/CV *per queue* with multiple threads..

mutex m;
queue<int> q;
condition cv;

void threadfunc()
{
  for(;;)
  {
    int m;
    {
      mutex::scoped_lock lock( m );
      while(q.empty())
        cv.wait( lock );
      m = q.pop();
    }
    if(m & 1) do_something_a();
    if(m & 2) do_something_b();
    if(m & 4) do_something_c();
  }
}

void notifyThread(bool a, bool b, bool c)
{
  {
     mutex::scoped_lock lock( m );
     q.push(a + 2 * b + 4 * c);
  }
  cv.notify_one();
}

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk