Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save UNIcodeX/a184506252ce3c8767ece47188e71e21 to your computer and use it in GitHub Desktop.
Save UNIcodeX/a184506252ce3c8767ece47188e71e21 to your computer and use it in GitHub Desktop.
Example of parallel processing NOT using pointers. NOTE: Sometimes one or more values does not get properly set in the array.
import locks, threadpool, strutils
{.experimental: "parallel".}
var
lock: Lock
a {.guard: lock.}: array[20, string]
initLock lock
proc process(s: string): string =
withLock lock:
return s
when isMainModule:
parallel:
for i in 0 ..< a.len:
a[i] = ^ spawn process($i)
sync()
echo a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment