about summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
authorarg@10ksloc.org <unknown>2006-08-03 13:50:37 +0200
committerarg@10ksloc.org <unknown>2006-08-03 13:50:37 +0200
commit4d55eee7547ff3b9e0d801c1aa86ba62286f56c4 (patch)
treece4ed4a3709105d2d236994fab45954d217222cf /main.c
parentd41b232b524afe38d4ce416f335571654f61abf0 (diff)
downloaddwm-4d55eee7547ff3b9e0d801c1aa86ba62286f56c4.tar.gz
applied Sanders Makefile patch
Diffstat (limited to 'main.c')
0 files changed, 0 insertions, 0 deletions
7fe9b000f2af928bd'>76ef75295 ^
9f9f0f081 ^
























5b96eaa95 ^
9f9f0f081 ^













1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

                  

                                         
                                                           



         


                                              
                          
























                                   
                                                         













                                                      
discard """
  outputsub: "101"
  errormsg: "'threadFunc' is not GC-safe"
  line: 39
  cmd: "nim $target --hints:on --threads:on $options $file"
"""

import os

var
  thr: array [0..5, TThread[tuple[a, b: int]]]

proc doNothing() = discard

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()