Explorar o código

create enough threads

ithewei %!s(int64=3) %!d(string=hai) anos
pai
achega
bbd6ae7fb3
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      cpputil/hthreadpool.h

+ 1 - 1
cpputil/hthreadpool.h

@@ -123,7 +123,7 @@ public:
     template<class Fn, class... Args>
     auto commit(Fn&& fn, Args&&... args) -> std::future<decltype(fn(args...))> {
         if (status == STOP) start();
-        if (idle_thread_num == 0 && cur_thread_num < max_thread_num) {
+        if (idle_thread_num <= tasks.size() && cur_thread_num < max_thread_num) {
             createThread();
         }
         using RetType = decltype(fn(args...));