summary refs log blame commit diff stats
path: root/tests/parallel/tguard2.nim
blob: 661893bb56ae9bf53465c2d824d1816e238d0053 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                   
                                    










                            
discard """
  errormsg: "unguarded access: c.i"
  line: 25
"""

type
  ProtectedCounter[T] = object
    i {.guard: L.}: T
    L: int

var
  c: ProtectedCounter[int]

c.i = 89

template atomicRead(L, x): untyped =
  {.locks: [L].}:
    x

proc main =
  {.locks: [c.L].}:
    inc c.i
    discard
  echo(atomicRead(c.L, c.i))
  echo c.i

main()