summary refs log blame commit diff stats
path: root/tests/niminaction/Chapter6/WikipediaStats/unguarded_access.nim
blob: 7bdde83970ec4ec2ff9bc2b2d5598dce42d17990 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                                       






                                      
                   






                           
discard """
  errormsg: "unguarded access: counter"
  line: 14
"""

import threadpool, locks

var counterLock: Lock
initLock(counterLock)
var counter {.guard: counterLock.} = 0

proc increment(x: int) =
  for i in 0 ..< x:
    let value = counter + 1
    counter = value

spawn increment(10_000)
spawn increment(10_000)
sync()
echo(counter)