diff options
author | Araq <rumpf_a@web.de> | 2011-07-10 15:48:13 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-07-10 15:48:13 +0200 |
commit | 5b96eaa9533e877b5b7f2c6bf1e291ccdfdfecef (patch) | |
tree | f58b139b00b6af984f716164c7a3d72761df514d /tests/threads/tthreadanalysis.nim | |
parent | 2565ff8ddec9fcf43fbda2fae6f04806c1bc6e8a (diff) | |
download | Nim-5b96eaa9533e877b5b7f2c6bf1e291ccdfdfecef.tar.gz |
preparations for 0.8.12
Diffstat (limited to 'tests/threads/tthreadanalysis.nim')
-rwxr-xr-x | tests/threads/tthreadanalysis.nim | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/threads/tthreadanalysis.nim b/tests/threads/tthreadanalysis.nim new file mode 100755 index 000000000..84545ddf7 --- /dev/null +++ b/tests/threads/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]) {.thread.} = + 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() + |