unguarded_access.nim 341 B

123456789101112131415161718192021
  1. discard """
  2. errormsg: "unguarded access: counter"
  3. line: 14
  4. """
  5. import threadpool, locks
  6. var counterLock: Lock
  7. initLock(counterLock)
  8. var counter {.guard: counterLock.} = 0
  9. proc increment(x: int) =
  10. for i in 0 ..< x:
  11. let value = counter + 1
  12. counter = value
  13. spawn increment(10_000)
  14. spawn increment(10_000)
  15. sync()
  16. echo(counter)