Repository navigation
kernel: Only setup kernel context globals once - #30537
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
de78532 to
50c14e5
Compare
|
Updated de78532 -> 50c14e5 (staticInitKernel_0 -> staticInitKernel_1, compare) |
stickies-v
left a comment
There was a problem hiding this comment.
ACK 50c14e5 . No behaviour change for bitcoind and bitcoin-qt, only affects the tests (and downstream).
The globals setup by the function calls when creating a new kernel context only need to be setup once. Calling them multiple times may be wasteful and has no apparent benefit. Besides kernel users potentially creating multiple contexts, this change may also be useful for tests creating multiple setups. Co-authored-by: stickies-v <[email protected]>
50c14e5 to
93fb0e7
Compare
|
Thanks for the suggestions @stickies-v, 50c14e5 -> 93fb0e7 (staticInitKernel_1 -> staticInitKernel_2, compare)
|
|
re-ACK 93fb0e7 |
|
Concept ACK. The context constructor isn't thread-safe. This can be tested with tsan and: diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index abe3d6a505..05d00eaf97 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -62,6 +62,7 @@
#include <algorithm>
#include <functional>
+#include <future>
#include <stdexcept>
using kernel::BlockTreeDB;
@@ -195,6 +196,13 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
AppInitParameterInteraction(*m_node.args);
LogInstance().StartLogging();
m_node.warnings = std::make_unique<node::Warnings>();
+ {
+ auto fun{[] { kernel::Context{}; }};
+ auto futs{std::array{
+ std::async(std::launch::async, fun),
+ std::async(std::launch::async, fun),
+ }};
+ }
m_node.kernel = std::make_unique<kernel::Context>();
m_node.ecc_context = std::make_unique<ECC_Context>();
SetupEnvironment();Which should print a data-race. So it seems fine to guard the code and only execute it once. |
|
ACK 93fb0e7 👝 Show signatureSignature: |
The globals setup by the function calls when creating a new kernel context only need to be setup once. Calling them multiple times may be wasteful and has no apparent benefit.
Besides kernel users potentially creating multiple contexts, this change may also be useful for tests creating multiple setups.