summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-10-12 12:45:18 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-10-12 12:45:18 +0200
commit8a2f481f9993dcfbc8e682710782ff2fe6725da4 (patch)
tree6be5420448a1dbd9029ec909d7f46bedcb85ad79 /lib
parentec253ada72a50f5fdca5c86fdf01b7099b1803aa (diff)
downloadNim-8a2f481f9993dcfbc8e682710782ff2fe6725da4.tar.gz
make threadpool care about minPoolSize
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/concurrency/threadpool.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index 2a0dbd2ca..0f23b7e85 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -448,12 +448,22 @@ proc nimSpawn3(fn: WorkerProc; data: pointer) {.compilerProc.} =
     if selectWorker(readyWorker, fn, data): return
     for i in 0.. <currentPoolSize:
       if selectWorker(addr(workersData[i]), fn, data): return
+
     # determine what to do, but keep in mind this is expensive too:
     # state.calls < maxPoolSize: warmup phase
     # (state.calls and 127) == 0: periodic check
     if state.calls < maxPoolSize or (state.calls and 127) == 0:
       # ensure the call to 'advice' is atomic:
       if tryAcquire(stateLock):
+        if currentPoolSize < minPoolSize:
+          if not workersData[currentPoolSize].initialized:
+            activateWorkerThread(currentPoolSize)
+          let w = addr(workersData[currentPoolSize])
+          atomicInc currentPoolSize
+          if selectWorker(w, fn, data):
+            release(stateLock)
+            return
+
         case advice(state)
         of doNothing: discard
         of doCreateThread: