1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-18 23:37:05 +01:00

Thread pool implementation

This commit is contained in:
2021-11-28 23:26:17 +00:00
parent 75485219d8
commit 5f192ad30f
6 changed files with 202 additions and 1 deletions

View File

@ -19,7 +19,8 @@ noinst_PROGRAMS = \
exPlot \
exPValue \
exRand \
exRootFinder
exRootFinder \
exThreadPool
exCompiledDoubleFunction_SOURCES = exCompiledDoubleFunction.cpp
exCompiledDoubleFunction_CXXFLAGS = $(COM_CXXFLAGS)
@ -73,4 +74,8 @@ exRootFinder_SOURCES = exRootFinder.cpp
exRootFinder_CXXFLAGS = $(COM_CXXFLAGS)
exRootFinder_LDFLAGS = -L../lib/.libs -lLatAnalyze
exThreadPool_SOURCES = exThreadPool.cpp
exThreadPool_CXXFLAGS = $(COM_CXXFLAGS)
exThreadPool_LDFLAGS = -L../lib/.libs -lLatAnalyze
ACLOCAL_AMFLAGS = -I .buildutils/m4

29
examples/exThreadPool.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <LatAnalyze/Core/ThreadPool.hpp>
using namespace std;
using namespace Latan;
int main(void)
{
ThreadPool pool;
cout << "Using " << pool.getThreadNum() << " threads" << endl;
for (unsigned int i = 1; i <= 20; ++i)
{
pool.addJob([i, &pool](void)
{
{
unique_lock<mutex> lock(pool.getMutex());
cout << "job " << i << " wait for " << i*100 << " ms" << endl;
}
this_thread::sleep_for(chrono::milliseconds(i*100));
{
unique_lock<mutex> lock(pool.getMutex());
cout << "job " << i << " done" << endl;
}
});
}
pool.terminate();
return EXIT_SUCCESS;
}