Mastering Nim has a malbolgia example that does what you're attempting here 
with [lockers](https://github.com/Araq/malebolgia?tab=readme-ov-file#lockers), 
and has this warning:

> A `ref T` pointer is implemented with reference counting and based on the 
> lifetime-tracking hooks. For performance reasons however, the reference 
> counting does not use atomic CPU instructions.

In the official documentation, the docs page points most prominently to [The 
Nim memory model](https://zevv.nl/nim-memory/) which skips what you're 
interested in, and the manual points to [Nim's Memory 
Management](https://nim-lang.org/docs/mm.html) which might explain that: there 
are different memory management options and they differ in whether the heap is 
shared or thread-local.

Reply via email to