mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-22 00:42:02 +01:00
Thread pool implementation
This commit is contained in:
29
examples/exThreadPool.cpp
Normal file
29
examples/exThreadPool.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user