13#include <boost/test/unit_test.hpp>
46#define WAIT_FOR(futures) \
48 for (const auto& f : futures) { \
49 BOOST_REQUIRE(f.wait_for(WAIT_TIMEOUT) == std::future_status::ready); \
57 return std::move(*
Assert(pool.
Submit(std::forward<F>(fn))));
87 std::counting_semaphore<>
blocker(0);
119 std::atomic<int> counter = 0;
122 std::vector<std::future<void>>
futures;
126 counter.fetch_add(i, std::memory_order_relaxed);
142 std::counting_semaphore<>
blocker(0);
168 std::atomic<bool> flag =
false;
171 flag.store(
true, std::memory_order_release);
196 const auto make_err{[&](
size_t n) {
return strprintf(
"error on thread #%s", n); }};
199 std::vector<std::future<void>>
futures;
216 std::counting_semaphore<>
blocker(0);
221 std::atomic<int> counter = 0;
224 counter.fetch_add(1, std::memory_order_relaxed);
247 std::promise<void>
signal;
254 signal.get_future().wait();
264 std::counting_semaphore<>
blocker(0);
300 std::atomic<int> counter{0};
302 std::vector<std::future<void>>
futures;
306 counter.fetch_add(1, std::memory_order_relaxed);
332 std::atomic<int> counter{0};
333 std::counting_semaphore<>
blocker(0);
337 counter.fetch_add(1, std::memory_order_relaxed);
363 std::this_thread::yield();
371 }
catch (std::exception&
e) {
387 std::counting_semaphore<>
blocker(0);
391 std::atomic<int> counter{0};
393 std::vector<std::future<void>>
futures;
415 std::counting_semaphore<>
blocker(0);
432 std::this_thread::yield();
#define Assert(val)
Identity function.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Fixed-size thread pool for running arbitrary tasks concurrently.
util::Expected< std::future< std::invoke_result_t< F > >, SubmitError > Submit(F &&fn) noexcept EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Enqueues a new task for asynchronous execution.
int GetNumCores()
Return the number of cores available on the current system.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr std::string_view SubmitErrorString(const ThreadPool::SubmitError err) noexcept
#define WAIT_FOR(futures)
BOOST_AUTO_TEST_CASE(submit_fails_with_correct_error)
constexpr auto WAIT_TIMEOUT
constexpr char POOL_NAME[]
auto Submit(ThreadPool &pool, F &&fn)
std::vector< std::future< void > > BlockWorkers(ThreadPool &threadPool, std::counting_semaphore<> &release_sem, size_t num_of_threads_to_block)
void UninterruptibleSleep(const std::chrono::microseconds &n)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.