diff --git a/analyze/algorithm/ObjectDetector.cpp b/analyze/algorithm/ObjectDetector.cpp index 06563fa..7deb2f6 100644 --- a/analyze/algorithm/ObjectDetector.cpp +++ b/analyze/algorithm/ObjectDetector.cpp @@ -99,20 +99,20 @@ namespace am::analyze::algorithm mThreadsCount); // threadpool could be replaced with std::async calls - //am::common::ThreadPool pool; + am::common::ThreadPool pool; for (size_t rowId = 0; rowId < mThreadsCount - 1; ++rowId) { ImageRowSegment row{rowId * rowHeight, rowId * rowHeight + rowHeight}; - futures.emplace_back(std::async(std::launch::async, startObjectsSearchInPair, - pair, row, *mConfiguration)); + // futures.emplace_back(std::async(std::launch::async, startObjectsSearchInPair, + // pair, row, *mConfiguration)); - //futures.emplace_back(pool.run(std::bind(&startObjectsSearchInPair, pair, row, *mConfiguration))); + futures.emplace_back(pool.run(std::bind(&startObjectsSearchInPair, pair, row, *mConfiguration))); } ImageRowSegment final_row{(mThreadsCount - 1) * rowHeight, pair.getHeight()}; - futures.emplace_back(std::async(std::launch::async, startObjectsSearchInPair, - pair, final_row, *mConfiguration)); - //futures.emplace_back(pool.run(std::bind(&startObjectsSearchInPair, pair, final_row, *mConfiguration))); + // futures.emplace_back(std::async(std::launch::async, startObjectsSearchInPair, + // pair, final_row, *mConfiguration)); + futures.emplace_back(pool.run(std::bind(&startObjectsSearchInPair, pair, final_row, *mConfiguration))); for (auto &e : futures) { res.emplace_back(e.get()); diff --git a/common/ThreadPool.hpp b/common/ThreadPool.hpp index 0fb03f0..b1841c3 100644 --- a/common/ThreadPool.hpp +++ b/common/ThreadPool.hpp @@ -9,8 +9,8 @@ namespace am::common class ThreadPool { public: - // according to test on CPU with Hyper-threading feature better to use mutiplier of 2 - // without hyper-threading - probably this mutiplier shall be 1, didn`t test yet + // according to test on CPU with Hyper-threading feature better to use multiplier of 2 + // without hyper-threading - probably this multiplier shall be 1, didn`t test yet explicit ThreadPool(unsigned num_threads = std::thread::hardware_concurrency() * 2) { while (num_threads--) @@ -39,14 +39,14 @@ namespace am::common template > std::future run(F &&f) const { - auto task = std::packaged_task(std::forward(f)); + auto task = std::packaged_task()>(std::forward(f)); auto future = task.get_future(); { std::lock_guard lock(mutex); // conversion to packaged_task erases the return type // so it can be stored in the queue. the future will still // contain the correct type - queue.push(std::packaged_task(std::move(task))); + queue.push(std::packaged_task()>(std::move(task))); } condvar.notify_one(); return future; @@ -69,7 +69,7 @@ namespace am::common private: std::vector threads; - mutable std::queue> queue; + mutable std::queue()>> queue; mutable std::mutex mutex; mutable std::condition_variable condvar; };