2021-11-28 23:26:17 +00:00
|
|
|
#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)
|
|
|
|
{
|
2021-11-28 23:51:56 +00:00
|
|
|
pool.critical([i](void)
|
2021-11-28 23:26:17 +00:00
|
|
|
{
|
|
|
|
cout << "job " << i << " wait for " << i*100 << " ms" << endl;
|
2021-11-28 23:51:56 +00:00
|
|
|
});
|
2021-11-28 23:26:17 +00:00
|
|
|
this_thread::sleep_for(chrono::milliseconds(i*100));
|
2021-11-28 23:51:56 +00:00
|
|
|
pool.critical([i](void)
|
2021-11-28 23:26:17 +00:00
|
|
|
{
|
|
|
|
cout << "job " << i << " done" << endl;
|
2021-11-28 23:51:56 +00:00
|
|
|
});
|
2021-11-28 23:26:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
pool.terminate();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|