race_condition.nim 232 B

123456789101112131415161718
  1. discard """
  2. action: compile
  3. """
  4. import threadpool
  5. var counter = 0
  6. proc increment(x: int) =
  7. for i in 0 ..< x:
  8. let value = counter + 1
  9. counter = value
  10. spawn increment(10_000)
  11. spawn increment(10_000)
  12. sync()
  13. echo(counter)