data_cond.wait(lk, [this]{return !data_queue.empty();});
invalid argument after compile with
g++ -std=c++0x -Wall -pthread threadpool.cc -o hello
originally from book is
data_cond.wait(lk, []{return !data_queue.empty();});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That looks rather like code from my book: C++ Concurrency in Action, especially with the lack of
[this]capture (a typo which will be fixed in the final printing).Unfortunately, there is a bug in g++ 4.5 and 4.6, where the compiler cannot handle lambdas with
[this]captures in class templates. This even applies to simple templates. You can see the problem with the simple classes below:Both g++ 4.5 and g++ 4.6 will give “invalid type argument” errors on the lambda in
Y::foo, but happily accept the same code inX::foo.Hopefully this will be fixed in a future version of g++. In the mean time, I would suggest using an explicit around the
waitcall: