我运行这段代码我得到了“的boost ::纤维:: lock_error”,不能弄清楚为什么
class ttt {
public:
~ttt() {
LOG(INFO);
flush();
}
bool flush() {
//std::lock_guard<boost::fibers::mutex> lock(_mutex);
LOG(INFO);
_mutex.lock();
LOG(INFO);
auto ret = flush_nonlock();
LOG(INFO);
_mutex.unlock();
LOG(INFO);
return ret;
}
private:
bool flush_nonlock() {
LOG(INFO);
return std::rand()%2;
}
boost::fibers::mutex _mutex;
};
int main() {
static ttt t;
std::cout << t.flush() << std::endl;
return 0;
}
我得到了
terminate called after throwing an instance of 'boost::fibers::lock_error'
what(): boost fiber: a deadlock is detected: Resource deadlock avoided
最后登录其打印是前_mutex.lock()。 如果t不是一个静态变量,它不会抛出任何错误。 如果我删除主func中的t.flush(),它不会抛出任何错误。 正如我在笔记中所写的那样使用std :: lock_guard,它旁边的行不会被打印。 我不明白为什么和什么差异的情况下,我尝试过。
我建立的代码使用GCC 5.4.0,用-O0
什么是LOG(INFO)? – snoopy
我试图找出程序抛出错误的哪一行。 – beegerous