GC_fullCollect on sync threadpool (#6107)
This commit is contained in:
parent
c245cfc1fd
commit
bdb653c415
1 changed files with 13 additions and 3 deletions
|
|
@ -526,10 +526,12 @@ proc nimSpawn4(fn: WorkerProc; data: pointer; id: ThreadId) {.compilerProc.} =
|
||||||
if selectWorker(addr(distinguishedData[id]), fn, data): break
|
if selectWorker(addr(distinguishedData[id]), fn, data): break
|
||||||
await(distinguishedData[id].readyForTask)
|
await(distinguishedData[id].readyForTask)
|
||||||
|
|
||||||
|
template spawnInAllThreads(e: untyped) =
|
||||||
|
## Spawn `e` on all of the threadpool threads.
|
||||||
|
for i in 0 .. <currentPoolSize:
|
||||||
|
pinnedSpawn(i, e)
|
||||||
|
|
||||||
proc sync*() =
|
proc syncAux() {.inline.} =
|
||||||
## a simple barrier to wait for all spawn'ed tasks. If you need more elaborate
|
|
||||||
## waiting, you have to use an explicit barrier.
|
|
||||||
var toRelease = 0
|
var toRelease = 0
|
||||||
while true:
|
while true:
|
||||||
var allReady = true
|
var allReady = true
|
||||||
|
|
@ -543,4 +545,12 @@ proc sync*() =
|
||||||
for i in 0 ..< toRelease:
|
for i in 0 ..< toRelease:
|
||||||
signal(gSomeReady)
|
signal(gSomeReady)
|
||||||
|
|
||||||
|
proc sync*(cleanup: bool = true) =
|
||||||
|
## A simple barrier to wait for all spawn'ed tasks. Calls `GC_fullCollect()`
|
||||||
|
## on all threads if `cleanup` is `true`. If you need more elaborate
|
||||||
|
## waiting, you have to use an explicit barrier.
|
||||||
|
syncAux()
|
||||||
|
if cleanup:
|
||||||
|
spawnInAllThreads GC_fullCollect()
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue