Boost scoped_lock failed every time
Asked Answered
A

1

0

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 :

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. When I use try_lock it doesn't failed by the condition is always false.

Searching on internet I found this 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.

Allerie answered 26/12, 2014 at 18:21 Comment(1)
how is mutex_ declared/defined? is it locked recursively?Slideaction
A
0

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.

Allerie answered 27/12, 2014 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.