summary refs log tree commit diff stats
path: root/tests/parallel/tptr_to_ref.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallel/tptr_to_ref.nim')
-rw-r--r--tests/parallel/tptr_to_ref.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/parallel/tptr_to_ref.nim b/tests/parallel/tptr_to_ref.nim
new file mode 100644
index 000000000..66d618481
--- /dev/null
+++ b/tests/parallel/tptr_to_ref.nim
@@ -0,0 +1,26 @@
+# bug #2854
+
+import locks, threadpool, osproc
+
+const MAX_WORKERS = 10
+
+type
+  Killer = object
+    lock: Lock
+    bailed {.guard: lock.}: bool
+    processes {.guard: lock.}: array[0..MAX_WORKERS-1, foreign ptr Process]
+
+template hold(lock: Lock, body: stmt) =
+  lock.acquire
+  defer: lock.release
+  {.locks: [lock].}:
+    body
+
+proc initKiller*(): Killer =
+  initLock(result.lock)
+  result.lock.hold:
+    result.bailed = false
+    for i, _ in result.processes:
+      result.processes[i] = nil
+
+var killer = initKiller()