| 17 | public: |
| 18 | virtual ~ThreadPoolTest() = default; |
| 19 | virtual bool run(int precision) { |
| 20 | std::vector<std::thread> threads; |
| 21 | for (int i = 0; i < 10; ++i) { |
| 22 | threads.emplace_back([i]() { |
| 23 | MNN::ThreadPool* threadPool = nullptr; |
| 24 | MNN::ThreadPool::init(10 - i, 0, threadPool); |
| 25 | // initializer |
| 26 | auto workIndex = threadPool->acquireWorkIndex(); |
| 27 | FUNC_PRINT(workIndex); |
| 28 | threadPool->active(); |
| 29 | ThreadPool::TASK task = std::make_pair([](int index) { |
| 30 | FUNC_PRINT(index); |
| 31 | std::this_thread::yield(); |
| 32 | }, 10); |
| 33 | threadPool->enqueue(&task, workIndex); |
| 34 | threadPool->deactive(); |
| 35 | threadPool->releaseWorkIndex(workIndex); |
| 36 | }); |
| 37 | } |
| 38 | for (auto& t : threads) { |
| 39 | t.join(); |
| 40 | } |
| 41 | MNN::ThreadPool::destroy(); |
| 42 | return true; |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | MNNTestSuiteRegister(ThreadPoolTest, "core/threadpool"); |
nothing calls this directly
no test coverage detected