mutex debugging routines: LocksHeld() and AssertLockHeld() #3329

pull gavinandresen wants to merge 1 commits into bitcoin:master from gavinandresen:syncdebug changing 3 files +23 −0
  1. gavinandresen commented at 7:59 AM on November 29, 2013: contributor

    Inspired by a Mike Hearn comment on #3276 -- adds a couple of mutex-related routines:

    AssertLockHeld("cs_foo") : if compiled -DDEBUG_LOCKORDER, walks the lock stack and makes sure the specified lock is held. If not, a message and the list of locks that ARE held are LogPrintf'ed and then assert(0) is called. Does nothing in normal builds.

    LocksHeld() : -DDEBUG_LOCKORDER-only routine: returns a human-readable string with all of the locks held. This can be very handy to call from within an interactive debugging session (and it is used by AssertLockHeld).

    I added AssertLockHeld("cs_main") to ProcessBlock as proof-of-concept; if we like this, adding AssertLockHeld calls to more routines can be done in subsequent pulls.

    PS: compiling with -DDEBUG_LOCKORDER in the new autotools-world means a 'make clean' and then something like: CXXFLAGS='-DDEBUG_LOCKORDER' ./configure ...

  2. mutex debugging routines: LocksHeld() and AssertLockHeld() c649637b6c
  3. laanwj commented at 8:03 AM on November 29, 2013: member

    ACK, sounds extremely useful for debugging.

    Many of the wallet functions also assume that the caller holds the lock, would be good to add assertions for cs_wallet there.

  4. BitcoinPullTester commented at 8:13 AM on November 29, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/c649637b6ccb270bd0160163e6e92c1456774286 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  5. mikehearn commented at 10:37 AM on November 29, 2013: contributor

    Looks good to me!

  6. sipa commented at 2:14 PM on November 29, 2013: member

    Hmm, why are we replicating the functionality in clang's static analyser at runtime? Use the macros in threadsafety.h if we want to do this.

  7. mikehearn commented at 2:19 PM on November 29, 2013: contributor

    Static analysis is useful but limited, especially when doing whole program analysis. There's no harm in having both.

  8. gavinandresen referenced this in commit a65edb104d on Dec 2, 2013
  9. gavinandresen merged this on Dec 2, 2013
  10. gavinandresen closed this on Dec 2, 2013

  11. gavinandresen deleted the branch on Mar 13, 2014
  12. Bushstar referenced this in commit 15c6df5835 on Apr 8, 2020
  13. Bushstar referenced this in commit 737b1eab8f on Apr 8, 2020
  14. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me