【发布时间】:2015-02-23 23:10:55
【问题描述】:
在一个类中,我想在这样的函数上使用互斥锁
void Agent::notify(Packet& packet, Peer peer) {
boost::mutex::scoped_lock lock(mutex_);
...
}
编译过程没有问题。但是当我执行程序时,boost 总是在这一行失败:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument
Abandon (core dumped)
我尝试使用lock() 或unlock 方法,但同样的问题。当我使用try_lock 时,它不会因为条件总是为假而失败。
在网上搜索我找到了这个https://svn.boost.org/trac/boost/ticket/9307。
但我认为问题出在我的程序上,但我不知道在哪里。在我的测试中,这个函数只有一个线程。
【问题讨论】:
-
mutex_是如何声明/定义的?它是递归锁定的吗?
标签: c++ boost boost-thread boost-mutex