Skip to content

Instantly share code, notes, and snippets.

@Varriount
Created February 12, 2016 22:39
Show Gist options
  • Save Varriount/b67a264a7139c900ba65 to your computer and use it in GitHub Desktop.
Save Varriount/b67a264a7139c900ba65 to your computer and use it in GitHub Desktop.
import tables, locks, threadpool
var hlock: Lock
var chats {.guard: hlock.}: Table[int64, int64]
template lock(a: Lock; body: stmt): auto =
a.acquire
defer: a.release
{.locks: [a].}:
body
proc test(c: ptr Table[int64, int64]) {.gcsafe.} =
lock hlock:
c[][1] = 2
proc main() =
var chatPtr: ptr Table[int64, int64]
lock hlock:
chats = initTable[int64, int64]()
chatPtr = addr(chats)
spawn test(chatPtr)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment