diff options
author | Araq <rumpf_a@web.de> | 2014-10-05 11:43:48 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-10-05 11:43:48 +0200 |
commit | 3354f7e0982d1db512cd2aad9cd78a52d3379d02 (patch) | |
tree | 3e198e221018e40d380410e1fd60d2a0a4c53ab6 /lib/pure | |
parent | 40601ada5f001bed7d9ce5f1e61f296540ae8869 (diff) | |
download | Nim-3354f7e0982d1db512cd2aad9cd78a52d3379d02.tar.gz |
fixes a race condition that caused '^' to hang
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/concurrency/threadpool.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index 7b0593b3e..fbd344e4e 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -95,7 +95,7 @@ type FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]' FlowVarBaseObj = object of RootObj - ready, usesCondVar: bool + ready, usesCondVar, awaited: bool cv: CondVar #\ # for 'awaitAny' support ai: ptr AwaitInfo @@ -129,8 +129,8 @@ type proc await*(fv: FlowVarBase) = ## waits until the value for the flowVar arrives. Usually it is not necessary ## to call this explicitly. - if fv.usesCondVar: - fv.usesCondVar = false + if fv.usesCondVar and not fv.awaited: + fv.awaited = true await(fv.cv) destroyCondVar(fv.cv) @@ -185,7 +185,8 @@ proc nimFlowVarSignal(fv: FlowVarBase) {.compilerProc.} = inc fv.ai.cv.counter release(fv.ai.cv.L) signal(fv.ai.cv.c) - if fv.usesCondVar: signal(fv.cv) + if fv.usesCondVar: + signal(fv.cv) proc awaitAndThen*[T](fv: FlowVar[T]; action: proc (x: T) {.closure.}) = ## blocks until the ``fv`` is available and then passes its value |