From 2848cdb18a1bcb0c1eb7ee4ac8807a5471432626 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 10 Nov 2022 16:54:39 +0800 Subject: [PATCH] fixes #13781; fixes #14901; add acyclic pragmas to FlowVar (#20804) * add acyclic pragmas to FlowVar * add testcases --- lib/pure/concurrency/threadpool.nim | 4 ++-- tests/parallel/tlet_spawn.nim | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index e17fc38b7..9d773dac5 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -102,7 +102,7 @@ type idx: int FlowVarBase* = ref FlowVarBaseObj ## Untyped base class for `FlowVar[T] <#FlowVar>`_. - FlowVarBaseObj = object of RootObj + FlowVarBaseObj {.acyclic.} = object of RootObj ready, usesSemaphore, awaited: bool cv: Semaphore # for 'blockUntilAny' support ai: ptr AwaitInfo @@ -111,7 +111,7 @@ type # be RootRef here otherwise the wrong GC keeps track of it! owner: pointer # ptr Worker - FlowVarObj[T] = object of FlowVarBaseObj + FlowVarObj[T] {.acyclic.} = object of FlowVarBaseObj blob: T FlowVar*[T] {.compilerproc.} = ref FlowVarObj[T] ## A data flow variable. diff --git a/tests/parallel/tlet_spawn.nim b/tests/parallel/tlet_spawn.nim index 62341d8f0..853ffc443 100644 --- a/tests/parallel/tlet_spawn.nim +++ b/tests/parallel/tlet_spawn.nim @@ -4,7 +4,7 @@ done999 999 ''' """ -import threadpool +import std/[threadpool, os] proc foo(): int = 999 @@ -17,3 +17,12 @@ proc main = echo "done", f, " ", b main() + +# bug #13781 +proc thread(): string = + os.sleep(1000) + return "ok" + +var fv = spawn thread() +sync() +doAssert ^fv == "ok"