Hello Nim gurus. I would like to implement something akin to RwLock (https://doc.rust-lang.org/std/sync/struct.RwLock.html) in Nim. Currently, I use a separate Lock, and use the shared data inside a withLock block.
var dataLock*: Lock
initLock(dataLock)
var data*: AppData
# ...
withLock dataLock: do(something(data))
However,
Is there any package that already provides this?
The first item might be implemented like this:
type DataWithLock = object
dataLock*: Lock
data* {.guard: dataLock.}: AppData
I'm not sure that guard will work without type definition, but it might.(never did so myself) It will compile with --threads:on only and will warn you if you are accessing to data without locking.