Threads
To enable thread support the --threads:on command line switch needs to be used. The system module then contains several threading primitives. See the threads and channels modules for the low level thread API. There are also high level parallelism constructs available. See spawn for further details.
Nim’s memory model for threads is quite different than that of other common programming languages (C, Pascal, Java): Each thread has its own (garbage collected) heap and sharing of memory is restricted to global variables. This helps to prevent race conditions. GC efficiency is improved quite a lot, because the GC never has to stop other threads and see what they reference.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .