C++ 每次启动作用域锁定都失败

C++ 每次启动作用域锁定都失败,c++,boost,boost-thread,boost-mutex,C++,Boost,Boost Thread,Boost Mutex,在一个类中,我想在这样的函数上使用互斥体 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<

在一个类中,我想在这样的函数上使用互斥体

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)
我尝试使用锁定或解锁方法,但同样的问题。当我使用try_lock时,它不会因为条件始终为false而失败

在网上搜索我找到了这个


但我认为问题在于我的程序,但我不知道在哪里。在我的测试中,这个函数中只有一个线程。

问题是,在程序中,使用互斥锁的线程需要处于相同的级别。然而,产生这个错误的线程是主线程。不是已创建的互斥体。

互斥体是如何声明/定义的?它是递归锁定的吗?