summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-11-07 01:54:47 +0100
committerAraq <rumpf_a@web.de>2014-11-07 01:54:47 +0100
commit06e9932e8ae6860b1c96c57138d2d56e51f7036d (patch)
tree8b2d62d2ea914022bb3a6fd68fea15541b8e4212
parentb5586264a0e0515f88f7ad4944bb987930fbd7b9 (diff)
downloadNim-06e9932e8ae6860b1c96c57138d2d56e51f7036d.tar.gz
fixes exhaustion bug and missing GC_ref code generation
-rw-r--r--compiler/lowerings.nim6
-rw-r--r--lib/pure/concurrency/threadpool.nim9
2 files changed, 10 insertions, 5 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim
index 8e5ffd48a..ae19f5366 100644
--- a/compiler/lowerings.nim
+++ b/compiler/lowerings.nim
@@ -286,6 +286,12 @@ proc createWrapperProc(f: PNode; threadParam, argsParam: PSym;
         typeToString(fv.typ.sons[1]))
     body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode,
       if fk == fvGC: "data" else: "blob", fv.info), call)
+    if fk == fvGC:
+      let incRefCall = newNodeI(nkCall, fv.info, 2)
+      incRefCall.sons[0] = newSymNode(createMagic("GCref", mGCref))
+      incRefCall.sons[1] = indirectAccess(threadLocalProm.newSymNode,
+                                          "data", fv.info)
+      body.add incRefCall
     if barrier == nil:
       # by now 'fv' is shared and thus might have beeen overwritten! we need
       # to use the thread-local view instead:
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index 727bbffa2..7959a6c92 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -100,7 +100,8 @@ type
     # for 'awaitAny' support
     ai: ptr AwaitInfo
     idx: int
-    data: RootRef  # we incRef and unref it to keep it alive
+    data: pointer  # we incRef and unref it to keep it alive; note this MUST NOT
+                   # be RootRef here otherwise the wrong GC keeps track of it!
     owner: pointer # ptr Worker
 
   FlowVarObj[T] = object of FlowVarBaseObj
@@ -162,10 +163,8 @@ proc finished(fv: FlowVarBase) =
   var waited = false
   acquire(q.lock)
   while not (q.len < q.data.len):
-    echo "EXHAUSTED!"
-    release(q.lock)
+    #echo "EXHAUSTED!"
     wakeupWorkerToProcessQueue(owner)
-    acquire(q.lock)
     wait(q.empty, q.lock)
     waited = true
   q.data[q.len] = cast[pointer](fv.data)
@@ -180,7 +179,7 @@ proc cleanFlowVars(w: ptr Worker) =
   acquire(q.lock)
   for i in 0 .. <q.len:
     GC_unref(cast[RootRef](q.data[i]))
-    echo "GC_unref"
+    #echo "GC_unref"
   q.len = 0
   release(q.lock)
   signal(q.empty)