tuserlocks.nim 271 B

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