Closed tsoj closed 4 months ago
Now works well with activeProducer=true
:
import malebolgia
import std/[os, atomics]
var
master = createMaster(activeProducer=true)
busyThreads: Atomic[int]
busyThreads.store 0
let mainThreadId = getThreadId()
proc findStartPositionsAndPlay() =
atomicInc busyThreads
echo "Started. Busy threads: ", busyThreads.load
sleep(1000)
if getThreadId() == mainThreadId:
sleep(10_000)
atomicDec busyThreads
echo "Finished. Busy threads: ", busyThreads.load
master.awaitAll:
for i in 1..100:
master.spawn findStartPositionsAndPlay()
When the main thread takes longer than most worker threads, it leads to low thread utilization, which is unfortunate.