tuserlocks.nim 242 B

123456789101112131415161718192021
  1. discard """
  2. matrix: "--threads:on"
  3. """
  4. import std/rlocks
  5. var r: RLock
  6. r.initRLock()
  7. doAssert r.tryAcquire()
  8. doAssert r.tryAcquire()
  9. r.release()
  10. r.release()
  11. block:
  12. var x = 12
  13. withRLock r:
  14. inc x
  15. doAssert x == 13
  16. r.deinitRLock()