Last active
April 13, 2020 16:48
-
-
Save UNIcodeX/b209b2118e3206acb96557d7d7b64310 to your computer and use it in GitHub Desktop.
Revisions
-
UNIcodeX revised this gist
Apr 13, 2020 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,10 +8,11 @@ var 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 -
UNIcodeX revised this gist
Apr 13, 2020 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,15 +8,20 @@ var 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 -
UNIcodeX revised this gist
Apr 13, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ import locks, threadpool, strutils # compile with: # nim c -r --threads:on -d:danger --gc:arc {.experimental: "parallel".} var -
UNIcodeX created this gist
Apr 13, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import locks, threadpool, strutils # compile with: # nim c -r --threads:on -d:danger --threadanalysis:off --gc:arc {.experimental: "parallel".} var lock: Lock a: array[20, string] initLock lock proc process(b: ptr array[20, string], s: string) = withLock lock: b[][parseInt(s)] = s when isMainModule: var b = addr(a) parallel: for i in 0 ..< a.len: spawn process(b, $i) sync() echo a