Created
April 19, 2015 21:09
-
-
Save ianpreston/bddb3084b3dbc30d0e8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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