tguard2.nim 342 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. errormsg: "unguarded access: c.i"
  3. line: 25
  4. """
  5. type
  6. ProtectedCounter[T] = object
  7. i {.guard: L.}: T
  8. L: int
  9. var
  10. c: ProtectedCounter[int]
  11. c.i = 89
  12. template atomicRead(L, x): untyped =
  13. {.locks: [L].}:
  14. x
  15. proc main =
  16. {.locks: [c.L].}:
  17. inc c.i
  18. discard
  19. echo(atomicRead(c.L, c.i))
  20. echo c.i
  21. main()