车库算在sf里吗# Living
s*u
1 楼
就是用condition_variable的时候,wait函数有一个参数是predicate,一般就是传一
个bool函数进去。
但我用gcc 4.8.1试了下这几种都不行(设计blocking queue):
_cond.wait(locker, [](){ return !_queue.empty() } );
_cond.wait(locker, []{ return !_queue.empty() } );
bool notEmpty(){return !_queue.empty() ;}
_cond.wait(locker, notEmpty);
错误是: 'this' was not captured for this lambda function
编译器问题?
顺便问下就是这种写法等效么:
while(_queue.empty())
_cond.wait(locker);
要是等效就不费事了。
个bool函数进去。
但我用gcc 4.8.1试了下这几种都不行(设计blocking queue):
_cond.wait(locker, [](){ return !_queue.empty() } );
_cond.wait(locker, []{ return !_queue.empty() } );
bool notEmpty(){return !_queue.empty() ;}
_cond.wait(locker, notEmpty);
错误是: 'this' was not captured for this lambda function
编译器问题?
顺便问下就是这种写法等效么:
while(_queue.empty())
_cond.wait(locker);
要是等效就不费事了。