-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[WIP] Add Clang thread safety analysis annotations: GUARDED_BY(lock) / EXCLUSIVE_LOCKS_REQUIRED(lock) #11226
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
[WIP] Add Clang thread safety analysis annotations: GUARDED_BY(lock) / EXCLUSIVE_LOCKS_REQUIRED(lock) #11226
Conversation
35a19eb
to
2c4a137
Compare
Awesome, I'm very happy to see someone work on this again. |
763b3d1
to
8729f81
Compare
You must have introduced a lock inversion, based on the Travis output. |
Squash commits |
b808f4c
to
d72e1e4
Compare
@sipa Thanks for letting me know! I've now removed the commit with the incorrectly added |
@promag Fixed! :-) Regarding the repeated Furthermore I've added an commit which renames renames |
09f74fe
to
21083dd
Compare
Concept ACK. This will generate some turbulence in terms of needing to rebase a ton of existing PRs, so maybe it makes sense to break this into several PRs which only touch given modules? In any case, excited to see this stuff happen. |
Concept ACK. Though I'm not sure what a good time to merge a huge, spread-out (though low-risk) change like this is. Maybe just before the 0.16 split? |
76fc04e
to
d87a8ef
Compare
@TheBlueMatt Sure, I can split this PR into multiple parts to ease reviewing! Just let me know which parts/modules to split it on :-) To avoid duplicating the commits in #10866 we should probably wait until #10866 is merged before splitting this PR up. Sounds reasonable? |
@sipa @TheBlueMatt @laanwj Thanks for reviewing and thanks for the encouragement! Do you happen to know which core developers that would be appropriate reviewers for this work (on a deeper The types of errors I might need some help from reviewers to avoid:
And perhaps most importantly: help reviewing that the added locks in this PR looks reasonable. In constrast to the annotations they alter run-time behaviour. There are a couple of |
9262e91
to
e555245
Compare
The code base contains 37 locks and in the process of documenting them I compiled this list of the initial creators of each lock. These lock introducers would likely be the best possible reviewers for the Bitcoin locks hall of fameLocks introduced by currently active core devs:
Previous lock introducers:
|
I'm now down to only four remaining These are the four cases I need help with:
For each of the above cases I see two alternatives:
|
I've now documented the five places where I'm opting out of thread-safety analysis for various reasons (using the Please let me know if there is a way to remove any of these opt-outs. |
|
@TheBlueMatt Thanks! I'll look into the suggested fixes. |
@jonasschnelli @TheBlueMatt In |
…wallet when accessing m_last_block_processed.
e329152
to
baf7c1f
Compare
Needs rebase. |
@MarcoFalke Do you mean a new PR with the Regarding rebasing – I suggest we merge (or close in the case of NACK) the locking related PR:s I currently have open and I'll rebase this PR on top of |
Something like e7f4866, but at this point I am not sure if it is going to help review a lot. |
Closing. Will split this into subsets and submit as separate PR:s. |
To facilitate reviewing the most important parts of this thread-safety PR (milestone 0.17.0) have been submitted as individual PR:s –
Reviews of these PR:s would be really appreciated! :-) I'll tackle the remaining parts once the above PR:s have been merged or closed. Complete thread safety annotation coverage is not far away now! :-) |
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org>
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
109a858 tests: Add missing locks to tests (practicalswift) Pull request description: Add missing locks to tests to satisfy lock requirements (such as `EXCLUSIVE_LOCKS_REQUIRED(...)` (Clang Thread Safety Analysis, see bitcoin#11226), `AssertLockHeld(...)` and implicit lock assumptions). Tree-SHA512: 1aaeb1da89df1779f02fcceff9d2f8ea24a3926d421f9ea305a19be04dd0b3e63d91f6c1ed22fb7e6988343f6a5288829a387ef872cfa7b6add57bd01046b5d9 Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/test/test_bitcoin.cpp
Add additional Clang thread safety analysis annotations as discussed with @sipa (#10866 (comment)) and others.
This is a follow-up to #10866
which this PR is rebased upon (awaiting merge of #10866). The first three commits (8a1dc09, e022990 and cbae151) can be reviewed in #10866.This PR contains three types of changes:
GUARDED_BY(...)
analysis below). Please review thoroughly.GUARDED_BY(...)
annotations to allow for Clang's thread safety analysis at compile-time. Does not change run-time behaviour.EXCLUSIVE_LOCKS_REQUIRED(...)
annotations to allow for Clang's thread safety analysis at compile-time. Does not change run-time behaviour.Background reading: The "C/C++ Thread Safety Analysis" paper (Hutchins, Ballman & Sutherland, 2014) paper describing Clang thread safety analysis and how it is used for the Google C++ codebase: