Skip to content

Commit fa0d3c4

Browse files
author
MarcoFalke
committed
test: Undo thread_local g_insecure_rand_ctx
1 parent b545a6e commit fa0d3c4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/test/test_bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
2424

25+
FastRandomContext g_insecure_rand_ctx;
26+
2527
void CConnmanTest::AddNode(CNode& node)
2628
{
2729
LOCK(g_connman->cs_vNodes);
@@ -37,8 +39,6 @@ void CConnmanTest::ClearNodes()
3739
g_connman->vNodes.clear();
3840
}
3941

40-
thread_local FastRandomContext g_insecure_rand_ctx;
41-
4242
std::ostream& operator<<(std::ostream& os, const uint256& num)
4343
{
4444
os << num.ToString();

src/test/test_bitcoin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::os
2626
return stream << static_cast<typename std::underlying_type<T>::type>(e);
2727
}
2828

29-
thread_local extern FastRandomContext g_insecure_rand_ctx;
29+
extern FastRandomContext g_insecure_rand_ctx;
3030

3131
static inline void SeedInsecureRand(bool deterministic = false)
3232
{

src/test/validation_block_tests.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
152152
// create a bunch of threads that repeatedly process a block generated above at random
153153
// this will create parallelism and randomness inside validation - the ValidationInterface
154154
// will subscribe to events generated during block validation and assert on ordering invariance
155-
boost::thread_group threads;
155+
std::vector<std::thread> threads;
156156
for (int i = 0; i < 10; i++) {
157-
threads.create_thread([&blocks]() {
157+
threads.emplace_back([&blocks]() {
158158
bool ignored;
159+
FastRandomContext insecure;
159160
for (int i = 0; i < 1000; i++) {
160-
auto block = blocks[InsecureRandRange(blocks.size() - 1)];
161+
auto block = blocks[insecure.randrange(blocks.size() - 1)];
161162
ProcessNewBlock(Params(), block, true, &ignored);
162163
}
163164

@@ -171,7 +172,9 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
171172
});
172173
}
173174

174-
threads.join_all();
175+
for (auto& t : threads) {
176+
t.join();
177+
}
175178
while (GetMainSignals().CallbacksPending() > 0) {
176179
MilliSleep(100);
177180
}

0 commit comments

Comments
 (0)