stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
pool.cpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023-2024 Amebis
4*/
5
6#include "pch.hpp"
7
8using namespace std;
9#ifdef _WIN32
10using namespace Microsoft::VisualStudio::CppUnitTestFramework;
11#endif
12
13namespace UnitTests
14{
15 constexpr size_t pool_capacity = 50;
16
17 TEST_CLASS(pool)
18 {
19 public:
20 TEST_METHOD(test)
21 {
22 using worker_t = unique_ptr<int>;
23 using pool_t = stdex::pool<worker_t>;
24 pool_t pool;
25 list<thread> workers;
26 for (auto n = thread::hardware_concurrency(); n--; ) {
27 workers.push_back(thread([](_Inout_ pool_t& pool)
28 {
29 for (size_t n = 10000; n--; ) {
30 worker_t el = pool.pop();
31 if (!el)
32 el.reset(new int(1));
33 pool.push(std::move(el));
34 }
35 }, ref(pool)));
36 }
37
38 for (auto& w : workers)
39 w.join();
40 }
41 };
42}
Per-NUMA pool of items.
Definition pool.hpp:24