Guest User

Untitled

a guest
Feb 12th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.35 KB | None | 0 0
  1. import tables, locks, threadpool
  2.  
  3. var hlock: Lock
  4. var chats {.guard: hlock.}: Table[int64, int64]
  5.  
  6. template lock(a: Lock; body: stmt): auto =
  7.   a.acquire
  8.   defer: a.release
  9.   {.locks: [a].}:
  10.     body
  11.  
  12. proc test() =
  13.   lock hlock:
  14.     chats[1] = 2
  15.  
  16. proc main() =
  17.   lock hlock:
  18.     chats = initTable[int64, int64]()
  19.   spawn test()
  20.  
  21. main()
Advertisement
Add Comment
Please, Sign In to add comment