tglobal.nim 556 B

12345678910111213141516171819202122232425262728293031
  1. block global:
  2. proc getState(): int =
  3. var state0 {.global.}: int
  4. inc state0
  5. result = state0
  6. for i in 0 ..< 3:
  7. doAssert getState() == i + 1
  8. for i in 0 ..< 3:
  9. once:
  10. doAssert i == 0
  11. block threadvar:
  12. proc getThreadState0(): int =
  13. var state0 {.threadvar.}: int
  14. inc state0
  15. result = state0
  16. for i in 0 ..< 3:
  17. doAssert getThreadState0() == i + 1
  18. proc getThreadState1(): int =
  19. var state1 {.threadvar.}: int
  20. inc state1
  21. result = state1
  22. for i in 0 ..< 3:
  23. doAssert getThreadState1() == i + 1