Created
February 12, 2016 22:39
-
-
Save Varriount/b67a264a7139c900ba65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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