Skip to content

Instantly share code, notes, and snippets.

@ianpreston
Created April 19, 2015 21:09
Show Gist options
  • Save ianpreston/bddb3084b3dbc30d0e8e to your computer and use it in GitHub Desktop.
Save ianpreston/bddb3084b3dbc30d0e8e to your computer and use it in GitHub Desktop.
import threadpool, math, os
randomize()
proc setRand(k: int, vals: var seq[int]) =
vals[k] = k * 2
if k < 7:
sleep(random(1000))
vals[k+1] = k * 2
proc doParallel() =
var vals = newSeq[int](8)
parallel:
for k in 0..vals.high:
spawn setRand(k, vals)
echo($vals)
doParallel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment