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.