简体   繁体   English

每次升压scoped_lock失败

[英]Boost scoped_lock failed every time

In a class, I want to use a mutex over a function like this 在一个类中,我想在这样的函数上使用互斥锁

void Agent::notify(Packet& packet, Peer peer) {
    boost::mutex::scoped_lock lock(mutex_);
    ...
}

No problem at the compilation process. 编译过程没有问题。 But when I execute the program, boost always fail at this line saying : 但是,当我执行程序时,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)

I try to use lock() or unlock methods, but the same problem. 我尝试使用lock()unlock方法,但是存在相同的问题。 When I use try_lock it doesn't failed by the condition is always false. 当我使用try_lock它不会失败,条件始终为false。

Searching on internet I found this https://svn.boost.org/trac/boost/ticket/9307 . 在互联网上搜索时,我发现了这个https://svn.boost.org/trac/boost/ticket/9307

But I think the problem is my program but I don't see where. 但是我认为问题出在我的程序上,但是我看不到哪里。 In my tests there is only one thread that go in this function. 在我的测试中,此函数只有一个线程。

The problem is that in the program the threads that use the mutex need to be at the same level . 问题在于,在程序中,使用互斥锁的线程必须处于同一级别 Yet the thread that created this error was the main thread. 但是,导致此错误的线程是主线程。 Not a created one. 不是创造的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM