uselocks.nim 247 B

1234567891011121314151617
  1. import locks
  2. import std/assertions
  3. type MyType* [T] = object
  4. lock: Lock
  5. proc createMyType*[T]: MyType[T] =
  6. initLock(result.lock)
  7. proc use* (m: var MyType): int =
  8. withLock m.lock:
  9. result = 3
  10. block:
  11. var l: Lock
  12. doAssert $l == "()"