summary refs log tree commit diff stats
path: root/tests/accept/compile
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-13 16:22:19 +0200
committerAraq <rumpf_a@web.de>2011-06-13 16:22:19 +0200
commit9f9f0f08187ebd5e83075960be7f24b087f5c6c4 (patch)
tree5cdcbf9f279b3dc3e5ede6da303513fb8ef5e228 /tests/accept/compile
parentc019d17561aff29db42d78de882d4f6f68b75c16 (diff)
downloadNim-9f9f0f08187ebd5e83075960be7f24b087f5c6c4.tar.gz
basic thread analysis working
Diffstat (limited to 'tests/accept/compile')
-rw-r--r--tests/accept/compile/tthreadanalysis.nim54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/accept/compile/tthreadanalysis.nim b/tests/accept/compile/tthreadanalysis.nim
new file mode 100644
index 000000000..0a1415fe3
--- /dev/null
+++ b/tests/accept/compile/tthreadanalysis.nim
@@ -0,0 +1,54 @@
+discard """
+  outputsub: "101"
+  cmd: "nimrod cc --hints:on --threads:on $# $#"
+"""
+
+import os
+
+const
+  noDeadlocks = defined(system.deadlocksPrevented)
+
+var
+  thr: array [0..5, TThread[tuple[a, b: int]]]
+
+proc doNothing() = nil
+
+type
+  PNode = ref TNode
+  TNode = object {.pure.}
+    le, ri: PNode
+    data: string
+
+var
+  root: PNode
+
+proc buildTree(depth: int): PNode =
+  if depth == 3: return nil
+  new(result)
+  result.le = buildTree(depth-1)
+  result.ri = buildTree(depth-1)
+  result.data = $depth
+
+proc echoLeTree(n: PNode) =
+  var it: PNode
+  it = nil
+  it = n
+  while it != nil:
+    echo it.data
+    it = it.le
+
+proc threadFunc(interval: tuple[a, b: int]) {.procvar.} = 
+  doNothing()
+  for i in interval.a..interval.b: 
+    var r = buildTree(i)
+    echoLeTree(r) # for local data
+  echoLeTree(root) # and the same for foreign data :-)
+
+proc main =
+  root = buildTree(5)
+  for i in 0..high(thr):
+    createThread(thr[i], threadFunc, (i*3, i*3+2))
+  joinThreads(thr)
+
+main()
+