Ask Your Question

Boost thread error

asked 2019-12-02 20:56:16 -0500

mrrius gravatar image

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-02 22:03:10 -0500

ahendrix gravatar image

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.

edit flag offensive delete link more


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.

mrrius gravatar image mrrius  ( 2019-12-03 01:25:46 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-03 02:10:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-12-02 20:56:16 -0500

Seen: 1,142 times

Last updated: Dec 02 '19