Thread Safety Analysis warnings #18636

issue hebasto opened this issue on April 14, 2020
  1. hebasto commented at 5:21 PM on April 14, 2020: member

    After removing spammy warnings (#18635), when compiling with -Wthread-safety some warnings are observed:

    $ make > /dev/null
    blockencodings.cpp:109:28: warning: reading variable 'vTxHashes' requires holding mutex 'cs' [-Wthread-safety-precise]
        for (size_t i = 0; i < vTxHashes.size(); i++) {
                               ^
    blockencodings.cpp:109:28: note: found near match 'pool->cs'
    blockencodings.cpp:110:50: warning: reading variable 'vTxHashes' requires holding mutex 'cs' [-Wthread-safety-precise]
            uint64_t shortid = cmpctblock.GetShortID(vTxHashes[i].first);
                                                     ^
    blockencodings.cpp:110:50: note: found near match 'pool->cs'
    blockencodings.cpp:114:47: warning: reading variable 'vTxHashes' requires holding mutex 'cs' [-Wthread-safety-precise]
                    txn_available[idit->second] = vTxHashes[i].second->GetSharedTx();
                                                  ^
    blockencodings.cpp:114:47: note: found near match 'pool->cs'
    3 warnings generated.
    net_processing.cpp:561:17: warning: reading variable 'lNodesAnnouncingHeaderAndIDs' requires holding mutex 'cs_main' [-Wthread-safety-analysis]
                if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
                    ^
    net_processing.cpp:564:34: warning: reading variable 'lNodesAnnouncingHeaderAndIDs' requires holding mutex 'cs_main' [-Wthread-safety-analysis]
                    connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
                                     ^
    net_processing.cpp:569:17: warning: reading variable 'lNodesAnnouncingHeaderAndIDs' requires holding mutex 'cs_main' [-Wthread-safety-analysis]
                    lNodesAnnouncingHeaderAndIDs.pop_front();
                    ^
    net_processing.cpp:572:13: warning: reading variable 'lNodesAnnouncingHeaderAndIDs' requires holding mutex 'cs_main' [-Wthread-safety-analysis]
                lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
                ^
    net_processing.cpp:1231:9: warning: calling function 'ProcessBlockAvailability' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
            ProcessBlockAvailability(pnode->GetId());
            ^
    net_processing.cpp:1232:30: warning: calling function 'State' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
            CNodeState &state = *State(pnode->GetId());
                                 ^
    net_processing.cpp:1236:18: warning: calling function 'PeerHasHeader' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
                    !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
                     ^
    net_processing.cpp:1236:51: warning: calling function 'PeerHasHeader' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
                    !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
                                                      ^
    net_processing.cpp:3450:33: warning: calling function 'State' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
                CNodeState *state = State(pnode->GetId());
                                    ^
    net_processing.cpp:3470:38: warning: calling function 'State' requires holding mutex 'cs_main' exclusively [-Wthread-safety-analysis]
                    CNodeState &state = *State(pnode->GetId());
                                         ^
    10 warnings generated.
    

    Tested compilers:

    $ clang --version
    clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    

    and

    % clang --version
    Apple clang version 11.0.3 (clang-1103.0.32.29)
    Target: x86_64-apple-darwin19.4.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    
  2. hebasto closed this on Apr 14, 2020

  3. practicalswift commented at 1:10 PM on April 15, 2020: contributor

    I'm not sure how those cases got merged in the first place. We have at least one Travis job with -Werror=thread-safety-analysis, no? :)

  4. hebasto commented at 1:15 PM on April 15, 2020: member

    I'm not sure how those cases got merged in the first place. We have at least one Travis job with -Werror=thread-safety-analysis, no? :)

    My setup was broken. That is why this issue was closed :)

    Nevertheless, mind looking into related #18635 and #18639?

  5. ajtowns commented at 6:24 AM on May 7, 2020: member

    These are just cases where thread-safety-precise is warning about locks being aliased, isn't it?

  6. hebasto commented at 6:28 AM on May 7, 2020: member

    These are just cases where thread-safety-precise is warning about locks being aliased, isn't it?

    Yes, it is. That's why I've closed this issue.

  7. hebasto commented at 6:36 AM on May 7, 2020: member

    @practicalswift

    I'm not sure how those cases got merged in the first place. We have at least one Travis job with -Werror=thread-safety-analysis, no? :)

    ~No, we haven't any, unfortunately.~ At least "macOS 10.14 native" builds with -Wthread-safety-analysis and -Werror=thread-safety-analysis flags.

    UPDATE: Oh, I see your #10866 :)

  8. DrahtBot locked this on Feb 15, 2022

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-24 21:14 UTC

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