import locks, threadpool, strutils # compile with: # nim c -r --threads:on -d:danger --gc:arc {.experimental: "parallel".} var lock: Lock a: array[20, string] initLock lock # Can do this explicitly with: # proc process(b: ptr array[20, string], s: string) = # or lazily with: proc process(b: ptr, s: string) = withLock lock: b[][parseInt(s)] = s when isMainModule: # could either explicitly define the pointer type # var ptra: ptr array[20, string] = addr(a) # or lazily with: var ptra = addr(a) parallel: for i in 0 ..< a.len: spawn process(ptra, $i) sync() echo a