fixes a race condition that caused '^' to hang

This commit is contained in:
Araq 2014-10-05 11:43:48 +02:00
commit 3354f7e098

View file

@ -95,7 +95,7 @@ type
FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]' FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]'
FlowVarBaseObj = object of RootObj FlowVarBaseObj = object of RootObj
ready, usesCondVar: bool ready, usesCondVar, awaited: bool
cv: CondVar #\ cv: CondVar #\
# for 'awaitAny' support # for 'awaitAny' support
ai: ptr AwaitInfo ai: ptr AwaitInfo
@ -129,8 +129,8 @@ type
proc await*(fv: FlowVarBase) = proc await*(fv: FlowVarBase) =
## waits until the value for the flowVar arrives. Usually it is not necessary ## waits until the value for the flowVar arrives. Usually it is not necessary
## to call this explicitly. ## to call this explicitly.
if fv.usesCondVar: if fv.usesCondVar and not fv.awaited:
fv.usesCondVar = false fv.awaited = true
await(fv.cv) await(fv.cv)
destroyCondVar(fv.cv) destroyCondVar(fv.cv)
@ -185,7 +185,8 @@ proc nimFlowVarSignal(fv: FlowVarBase) {.compilerProc.} =
inc fv.ai.cv.counter inc fv.ai.cv.counter
release(fv.ai.cv.L) release(fv.ai.cv.L)
signal(fv.ai.cv.c) 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.}) = proc awaitAndThen*[T](fv: FlowVar[T]; action: proc (x: T) {.closure.}) =
## blocks until the ``fv`` is available and then passes its value ## blocks until the ``fv`` is available and then passes its value