Thread pool prototype

This commit is contained in:
KiritoDev 2022-03-21 21:38:16 -06:00 committed by Kenix3
parent becfaa2cfb
commit 8d53e09269
3 changed files with 260 additions and 4 deletions

View file

@ -3,6 +3,7 @@
#include "impl.h"
#include "utils/mutils.h"
#include "ctpl/ctpl_stl.h"
#include <thread>
#ifdef _WIN32
@ -68,6 +69,9 @@ void startWorker() {
std::vector<std::string> files;
Util::dirscan(path, files);
std::vector<std::string> xmlFiles;
const int num_threads = std::thread::hardware_concurrency();
ctpl::thread_pool pool(num_threads / 2);
for(auto &file : files) {
if (file.find(".xml") != std::string::npos) xmlFiles.push_back(file);
}
@ -76,8 +80,9 @@ void startWorker() {
if(single_thread) {
ExtractFunc(file);
} else {
std::thread thread_object(ExtractFunc, file);
thread_object.detach();
pool.push([file](int) {
ExtractFunc(file);
});
}
}