summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-08-01 08:02:23 +0800
committerGitHub <noreply@github.com>2022-07-31 20:02:23 -0400
commita8590d6707ebc5e1e278cd45f43acd15f5f92fe4 (patch)
treee7671ebe2568ec4f2d103cfab0b6ded51a92e9d7
parent86fc78a9c0a9bfcc344cb5bb998cd7da21d8b9aa (diff)
downloadNim-a8590d6707ebc5e1e278cd45f43acd15f5f92fe4.tar.gz
[ORC] replace threadpool with createThread in the runnableExamples (#20106)
replace threadpool with createThreads in the runnableExamples
-rw-r--r--lib/pure/random.nim25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/pure/random.nim b/lib/pure/random.nim
index 7676ce6cf..bcf6156af 100644
--- a/lib/pure/random.nim
+++ b/lib/pure/random.nim
@@ -178,24 +178,31 @@ proc skipRandomNumbers*(s: var Rand) =
   ## **See also:**
   ## * `next proc<#next,Rand>`_
   runnableExamples("--threads:on"):
-    import std/[random, threadpool]
+    import std/random
 
-    const spawns = 4
     const numbers = 100000
 
-    proc randomSum(r: Rand): int =
-      var r = r
+    var
+      thr: array[0..3, Thread[(Rand, int)]]
+      vals: array[0..3, int]
+
+    proc randomSum(params: tuple[r: Rand, index: int]) {.thread.} =
+      var r = params.r
       for i in 1..numbers:
-        result += r.rand(0..10)
+        vals[params.index] += r.rand(0..10)
 
     var r = initRand(2019)
-    var vals: array[spawns, FlowVar[int]]
-    for val in vals.mitems:
-      val = spawn randomSum(r)
+    for i in 0..<thr.len:
+      createThread(thr[i], randomSum, (r, i))
       r.skipRandomNumbers()
 
+    joinThreads(thr)
+
     for val in vals:
-      doAssert abs(^val - numbers * 5) / numbers < 0.1
+      doAssert abs(val - numbers * 5) / numbers < 0.1
+
+    doAssert vals == [501737, 497901, 500683, 500157]
+
 
   when defined(js):
     const helper = [0xbeac0467u32, 0xd86b048bu32]