Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1095795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:10:56+00:00 2026-05-17T00:10:56+00:00

I’m writing a unit test with Boost.Unit, and I would like to include basic

  • 0

I’m writing a unit test with Boost.Unit, and I would like to include basic tests for deadlocks in the code I’m testing. My first idea was to set a deadline timer in one thread while running the test in another that is expected to finish well before the deadline. When the timer goes off, assert that the thread is not running or not interruptible. In what ways could I detect deadlocks more precisely?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:10:57+00:00Added an answer on May 17, 2026 at 12:10 am

    One question is, are you testing for actual deadlocks (i.e. to see if a deadlock HAS happened) or potential deadlocks (i.e. to see if a deadlock COULD happen)?

    If you only care about detecting actual deadlocks, then something like what you describe can work. However, I’m not sure that will be all that useful, since no matter how many times you run your test, there will always be the possibility that a deadlock might still occur in the future, if the inter-thread timing ends up just exactly wrong. This is an area where multithreaded programming differs from single-threaded programming: in a multithreaded program, successfully running the program once (or even a million times) does not prove it’s correct.

    The only way to guarantee that your code won’t deadlock is to verify that whenever threads hold more than one lock at a time, they all aquire the locks in the same order. The easiest way to do that is to make sure no thread ever holds more than one lock at a time, but that’s not always possible. Given that, another approach is to simply eyeball the code until you’ve proven to your own satisfaction that a single locking order is followed in all cases. But that’s not always practical either, especially if the code is complicated. (btw, it’s always good to make multithreaded code as brutally simple as you possibly can, for precisely this sort of reason).

    If eyeballing the code isn’t sufficient, the last thing you can do is instrument your lock-acquisitions: The easiest way to do this (if your code can run under Linux) is to run your code under helgrind. If you can’t do that, an alternate method is to wrap your lock/unlock calls in a function that logs which thread was locking/unlocking which mutex, and later on, parse the log to detect lock-ordering inconsistencies “post mortem”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.