mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 11:54:11 +00:00
removed flawed thread analysis pass
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
file: "tthreadanalysis2.nim"
|
||||
line: 42
|
||||
errormsg: "write to foreign heap"
|
||||
line: 37
|
||||
errormsg: "'threadFunc' is not GC-safe"
|
||||
cmd: "nimrod $target --hints:on --threads:on $options $file"
|
||||
"""
|
||||
|
||||
@@ -10,7 +10,7 @@ import os
|
||||
var
|
||||
thr: array [0..5, TThread[tuple[a, b: int]]]
|
||||
|
||||
proc doNothing() = nil
|
||||
proc doNothing() = discard
|
||||
|
||||
type
|
||||
PNode = ref TNode
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
discard """
|
||||
file: "tthreadanalysis3.nim"
|
||||
line: 35
|
||||
errormsg: "write to foreign heap"
|
||||
cmd: "nimrod $target --hints:on --threads:on $options $file"
|
||||
"""
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user