tester: threading tests added

This commit is contained in:
Araq 2011-11-19 02:05:16 +01:00
commit 62aa8bed3b
9 changed files with 96 additions and 29 deletions

View file

@ -40,7 +40,7 @@ proc threadFunc(interval: tuple[a, b: int]) {.thread.} =
var r = buildTree(i)
echoLeTree(r) # for local data
root = buildTree(2) # BAD!
echoLeTree(root) # and the same for foreign data :-)
#echoLeTree(root) # and the same for foreign data :-)
proc main =
root = buildTree(5)

View file

@ -0,0 +1,51 @@
discard """
file: "tthreadanalysis3.nim"
line: 35
errormsg: "write to foreign heap"
cmd: "nimrod cc --hints:on --threads:on $# $#"
"""
import os
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 = 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*100, i*100+50))
joinThreads(thr)
main()

View file

@ -1,6 +1,12 @@
discard """
line: 12
errormsg: "write to foreign heap"
cmd: "nimrod cc --hints:on --threads:on $# $#"
"""
var
global: string = "test string"
t: TThread[string]
t: TThread[void]
proc horrible() {.thread.} =
global = "string in thread local heap!"