mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
make threadpool care about minPoolSize
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user