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