瀏覽代碼

create enough threads

ithewei 3 年之前
父節點
當前提交
bbd6ae7fb3
共有 1 個文件被更改,包括 1 次插入1 次删除
  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...));