Skip to content

Commit

Permalink
Using condition_variable wait w/ predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
egalli64 committed Aug 18, 2013
1 parent b075897 commit 432407d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions thread/condQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ class Conditional
while(true)
{
std::unique_lock<std::mutex> lock(mutex_);
/*
while(queue_.empty())
{
std::cout << "waiting queue" << std::endl;
cond_.wait(lock);
// if(queue_.empty())
// std::cout << "spurious ";
}
*/
cond_.wait(lock, [this] { return !queue_.empty(); });

int message = queue_.front();
queue_.pop();

Expand Down

0 comments on commit 432407d

Please sign in to comment.