Robotics StackExchange | Archived questions

Boost thread error

I got this error at some point during node execution and I don't know why. The time it happened seems random but it is always occur. When I tried to debug with Valgrind (launching the node with valgrind prefix), this error never happened and the node never terminate. Anyone familiar with this error?

 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

Asked by mrrius on 2019-12-02 21:56:16 UTC

Comments

Answers

I've seen errors like this a few times; they usually happen when you attempt to lock the mutex after it has been destructed. I suggest you run your code in gdb, and look at the contents of the mutex and the stack trace when your program crashes.

If you have more than one thread, you may want to look at all of the threads to see what they're doing when your program crashes. You can use the thread apply all backtrace command in gdb to get a back trace from every thread at the time of the crash.

If you can, I also suggest that you set your system to produce core dumps (change the core dump size limit), collect several core dumps, and try to determine what they have in common (maybe crashes in the same function, or crashes on the same mutex but different functions, etc)

Errors in threading code can be very tricky to spot and debug. Keep at it, and you'll eventually figure it out.

Asked by ahendrix on 2019-12-02 23:03:10 UTC

Comments

The problem when I trace the gdb result stem from ros spin. I don't really understand because it seems the thread error is caused by thread used by ros itself and not my code because in my code, I never access any mutex. Is there any suggestion what possble cause because my code is too simple to debug. I only subscribe to a topic and create a callback that echo the message. Without doing anything, it crashes sometimes.

Asked by mrrius on 2019-12-03 02:25:46 UTC

Can you please provide information on how you installed ROS, which platform this is, OS and version, version of Boost etc. Do this by editing your original question. Not in a comment.

Asked by gvdhoorn on 2019-12-03 03:10:30 UTC

I have a similar problem on ROS Melodic (Ubuntu 18.04). Any news?

Asked by bach on 2021-07-08 12:28:40 UTC