Simplify mutex locking, fix deadlocks #480

pull gavinandresen wants to merge 3 commits into bitcoin:master from gavinandresen:deadlocks changing 11 files +689 −746
  1. gavinandresen commented at 4:46 PM on August 31, 2011: contributor

    I collapsed several wallet mutexes into two: one for the keystore, and one for the wallet. That fixes many potential deadlocks due to wallet code acquiring the various locks in different orders.

    And I fixed several other potential deadlocks by requiring that code that needs both the cs_main and cs_wallet mutexes acquire them in that order.

    One somewhat scary semantic change: Transaction times reported by in the rpc interface and in the GUI are now always the time the transaction was received by this node (and not the average-time-of-the-last-n-blocks-that-the-transaction-ended-up-in).

    Having transaction times change as they were confirmed was a mistake, in my humble opinion, but the main reason I changed this behavior was so that CWallet::GetTxTime() doesn't require the cs_main lock.

    I'd like to further compartmentalize locking, but that's a task for another day...

  2. Highlight mis-matching locks b0243da77c
  3. Fix rpc-hanging deadlocks
    Collapsed multiple wallet mutexes to a single cs_wallet, to avoid deadlocks with wallet methods that acquired locks in different order.
    Also change master RPC call handler to acquire cs_main and cs_wallet locks before executing RPC calls; requiring each RPC call to acquire the right set of locks in the right order was too error-prone.
    6cc4a62c0e
  4. Fixed potential deadlocks in GUI code.
    Also changed semantics of CWalletTx::GetTxTime(); now always returns the time the transaction was received by this node, not the average block time.
    And added information about -DDEBUG_LOCKORDER to coding.txt.
    471426fb3b
  5. gavinandresen referenced this in commit cb6c4b883d on Aug 31, 2011
  6. gavinandresen merged this on Aug 31, 2011
  7. gavinandresen closed this on Aug 31, 2011

  8. dexX7 referenced this in commit 378ae44c12 on Jul 7, 2017
  9. achow101 referenced this in commit ce963f609c on Jul 14, 2018
  10. lateminer referenced this in commit 79e7a13b07 on Jan 22, 2019
  11. sipa referenced this in commit cc05fa919a on Mar 30, 2019
  12. sipa referenced this in commit 54245985fb on Mar 31, 2019
  13. LongShao007 referenced this in commit 3d9a3d2063 on Jul 15, 2019
  14. fjahr referenced this in commit f54c6c5083 on Jul 24, 2019
  15. kallewoof referenced this in commit 2d465aa9cd on Oct 4, 2019
  16. rajarshimaitra referenced this in commit 068b070005 on Aug 5, 2021
  17. DrahtBot locked this on Sep 8, 2021
Contributors

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-05-02 15:16 UTC

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