Quote Originally Posted by pheres View Post
So I end up with:


Code:
lock mutex;
while(true)
{
   wait for condition;
   if(vector != empty)
   {
       newvec = vector;
       vector.clear();
       unlock mutex;
       consume_all(newvec);
       lock mutex;
   }
}
unlock mutex;
but what if a thing is produced between consume_all and lock? wouldn't it be better to remove the unlock/lock from the inner if?
Since the data being processed is the "newvec", the producer is free do fill in vector, and as long as the "condition" you wait for isn't transient (in which case you have a race-condition in the condition itself, and you should fix that), you should be fine.

--
Mats