summary refs log tree commit diff stats
path: root/tests/parallel/tguard2.nim
blob: 661893bb56ae9bf53465c2d824d1816e238d0053 (plain) (blame)
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
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()