uselocks.nim 277 B

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