MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BlockWorkers

Function BlockWorkers

src/test/threadpool_tests.cpp:67–78  ·  view source on GitHub ↗

Block a number of worker threads by submitting tasks that wait on `release_sem`. Returns the futures of the blocking tasks, ensuring all have started and are waiting.

Source from the content-addressed store, hash-verified

65// Block a number of worker threads by submitting tasks that wait on `release_sem`.
66// Returns the futures of the blocking tasks, ensuring all have started and are waiting.
67std::vector<std::future<void>> BlockWorkers(ThreadPool& threadPool, std::counting_semaphore<>& release_sem, size_t num_of_threads_to_block)
68{
69 assert(threadPool.WorkersCount() >= num_of_threads_to_block);
70 std::latch ready{static_cast<std::ptrdiff_t>(num_of_threads_to_block)};
71 std::vector<std::future<void>> blocking_tasks(num_of_threads_to_block);
72 for (auto& f : blocking_tasks) f = Submit(threadPool, [&] {
73 ready.count_down();
74 release_sem.acquire();
75 });
76 ready.wait();
77 return blocking_tasks;
78}
79
80// Test 0, submit task to a non-started, interrupted, or stopped pool
81BOOST_AUTO_TEST_CASE(submit_fails_with_correct_error)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 2

SubmitFunction · 0.85
waitMethod · 0.45

Tested by

no test coverage detected