GC safety effect
We call a proc p GC safe when it doesn’t access any global variable that contains GC’ed memory (string, seq, ref or a closure) either directly or indirectly through a call to a GC unsafe proc.
The GC safety property is usually inferred. The inference for GC safety is analogous to the inference for exception tracking.
The gcsafe annotation can be used to mark a proc to be gcsafe, otherwise this property is inferred by the compiler. Note that noSideEffect implies gcsafe.
Routines that are imported from C are always assumed to be gcsafe.
To override the compiler’s gcsafety analysis a {.cast(gcsafe).} pragma block can be used:
var
someGlobal: string = "some string here"
perThread {.threadvar.}: string
proc setPerThread() =
{.cast(gcsafe).}:
deepCopy(perThread, someGlobal)
See also:
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .