Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve thread safety analysis by propagating some negative capabilities #25175

Merged
merged 2 commits into from
May 20, 2022

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented May 20, 2022

This PR is a follow-up for #22778 and #24062, and it seems required for #24931.

See details in the commit messages.

hebasto added 2 commits May 20, 2022 13:25
Could be verified with
$ ./configure CC=clang CXX=clang++ CXXFLAGS='-Wthread-safety -Wthread-safety-negative'
$ make clean
$ make 2>&1 | grep m_most_recent_block_mutex
Could be verified with
$ ./configure CC=clang CXX=clang++ CXXFLAGS='-Wthread-safety -Wthread-safety-negative'
$ make clean
$ make 2>&1 | grep m_tx_relay_mutex
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -472,15 +472,16 @@ class PeerManagerImpl final : public PeerManager
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void BlockChecked(const CBlock& block, const BlockValidationState& state) override
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how useful it is to annotate interface functions with member mutexes. The only allowed caller can't see the mutex, as it is private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An annotation is not for a caller, rather for Clang Thread Safety Analysis C++ extension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(An external caller (accessing via the virtual/override) can't see the mutex, but an in-class caller could)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just thinking that it would be incredibly unlikely or even wrong to even have an in-class caller.

@jonatack
Copy link
Member

Concept ACK

@ajtowns
Copy link
Contributor

ajtowns commented May 20, 2022

ACK 2b3373c

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2b3373c

@maflcko maflcko merged commit aac99fa into bitcoin:master May 20, 2022
@hebasto hebasto deleted the 220520-nega branch May 20, 2022 17:58
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
@bitcoin bitcoin locked and limited conversation to collaborators May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants