@@ -124,6 +124,7 @@
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pool.cpp" />
|
||||
<ClCompile Include="ring.cpp" />
|
||||
<ClCompile Include="sgml.cpp" />
|
||||
<ClCompile Include="stream.cpp" />
|
||||
|
@@ -42,6 +42,9 @@
|
||||
<ClCompile Include="watchdog.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pool.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.hpp">
|
||||
|
@@ -16,10 +16,12 @@
|
||||
#include <stdex/mapping.hpp>
|
||||
#include <stdex/math.hpp>
|
||||
#include <stdex/parser.hpp>
|
||||
#include <stdex/pool.hpp>
|
||||
#include <stdex/progress.hpp>
|
||||
#include <stdex/ring.hpp>
|
||||
#include <stdex/sgml.hpp>
|
||||
#include <stdex/socket.hpp>
|
||||
#include <stdex/spinlock.hpp>
|
||||
#include <stdex/stream.hpp>
|
||||
#include <stdex/string.hpp>
|
||||
#include <stdex/sys_info.hpp>
|
||||
@@ -32,4 +34,5 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <thread>
|
||||
|
42
UnitTests/pool.cpp
Normal file
42
UnitTests/pool.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
using namespace std;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
constexpr size_t capacity = 50;
|
||||
|
||||
TEST_CLASS(pool)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(test)
|
||||
{
|
||||
using worker_t = unique_ptr<int>;
|
||||
using pool_t = stdex::pool<worker_t>;
|
||||
pool_t pool;
|
||||
list<thread> workers;
|
||||
for (auto n = thread::hardware_concurrency(); n--; ) {
|
||||
workers.push_back(std::move(thread([](_Inout_ pool_t& pool)
|
||||
{
|
||||
for (size_t n = 10000; n--; ) {
|
||||
worker_t el = move(pool.pop());
|
||||
if (!el)
|
||||
el.reset(new int(1));
|
||||
pool.push(move(el));
|
||||
}
|
||||
}, ref(pool))));
|
||||
}
|
||||
|
||||
for (auto& w : workers)
|
||||
w.join();
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user