diff options
Diffstat (limited to 'tests/parallel')
-rw-r--r-- | tests/parallel/tblocking_channel.nim | 4 | ||||
-rw-r--r-- | tests/parallel/tconvexhull.nim | 7 | ||||
-rw-r--r-- | tests/parallel/tdeepcopy.nim | 60 | ||||
-rw-r--r-- | tests/parallel/tdeepcopy2.nim | 6 | ||||
-rw-r--r-- | tests/parallel/tdisjoint_slice1.nim | 63 | ||||
-rw-r--r-- | tests/parallel/tdisjoint_slice2.nim | 40 | ||||
-rw-r--r-- | tests/parallel/tmissing_deepcopy.nim | 6 | ||||
-rw-r--r-- | tests/parallel/tsendtwice.nim | 4 | ||||
-rw-r--r-- | tests/parallel/twaitany.nim | 8 |
9 files changed, 111 insertions, 87 deletions
diff --git a/tests/parallel/tblocking_channel.nim b/tests/parallel/tblocking_channel.nim index 8b8b49454..6ec0e1588 100644 --- a/tests/parallel/tblocking_channel.nim +++ b/tests/parallel/tblocking_channel.nim @@ -25,11 +25,11 @@ proc emitter() = spawn emitter() # At this point emitter should be stuck in `send` -sleep(100) # Sleep a bit to ensure that it is still stuck +sleep(50) # Sleep a bit to ensure that it is still stuck doAssert(not msgSent) spawn receiver() -sleep(100) # Sleep a bit to let receicer consume the messages +sleep(50) # Sleep a bit to let receicer consume the messages doAssert(msgSent) # Sender should be unblocked doAssert(chan.trySend(4)) diff --git a/tests/parallel/tconvexhull.nim b/tests/parallel/tconvexhull.nim index 184a131a2..ebadb874d 100644 --- a/tests/parallel/tconvexhull.nim +++ b/tests/parallel/tconvexhull.nim @@ -51,12 +51,11 @@ proc convex_hull[T](points: var seq[T], cmp: proc(x, y: T): int {.closure.}) : s ul[k] = spawn half[T](points, k == 0) result = concat(^ul[0], ^ul[1]) -var s = map(toSeq(0..99999), proc(x: int): Point = (float(x div 1000), float(x mod 1000))) +var s = map(toSeq(0..9999), proc(x: int): Point = (float(x div 100), float(x mod 100))) # On some runs, this pool size reduction will set the "shutdown" attribute on the # worker thread that executes our spawned task, before we can read the flowvars. setMaxPoolSize 2 -#echo convex_hull[Point](s, cmpPoint) -for i in 0..5: +for i in 0..2: doAssert convex_hull[Point](s, cmpPoint) == - @[(0.0, 0.0), (99.0, 0.0), (99.0, 999.0), (0.0, 999.0)] + @[(0.0, 0.0), (99.0, 0.0), (99.0, 99.0), (0.0, 99.0)] diff --git a/tests/parallel/tdeepcopy.nim b/tests/parallel/tdeepcopy.nim index 84e2edf3f..499ea94d4 100644 --- a/tests/parallel/tdeepcopy.nim +++ b/tests/parallel/tdeepcopy.nim @@ -1,18 +1,54 @@ discard """ - output: '''13 abc''' + output: ''' +13 abc +called deepCopy for int +called deepCopy for int +done999 999 +''' """ -type - PBinaryTree = ref object - le, ri: PBinaryTree - value: int +import threadpool +block one: + type + PBinaryTree = ref object + le, ri: PBinaryTree + value: int -proc main = - var x: PBinaryTree - deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13)))) - var y: string - deepCopy y, "abc" - echo x.ri.le.value, " ", y + proc main = + var x: PBinaryTree + deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13)))) + var y: string + deepCopy y, "abc" + echo x.ri.le.value, " ", y -main() + main() + + +block two: + type + Bar[T] = object + x: T + + proc `=deepCopy`[T](b: ref Bar[T]): ref Bar[T] = + result.new + result.x = b.x + when T is int: + echo "called deepCopy for int" + else: + echo "called deepCopy for something else" + + proc foo(b: ref Bar[int]): int = 999 + +# test that the disjoint checker deals with 'a = spawn f(); g = spawn f()': + + proc main = + var dummy: ref Bar[int] + new(dummy) + dummy.x = 44 + #parallel: + let f = spawn foo(dummy) + let b = spawn foo(dummy) + echo "done", ^f, " ", ^b + + main() diff --git a/tests/parallel/tdeepcopy2.nim b/tests/parallel/tdeepcopy2.nim index 2ad623ed1..a9caab604 100644 --- a/tests/parallel/tdeepcopy2.nim +++ b/tests/parallel/tdeepcopy2.nim @@ -1,7 +1,9 @@ discard """ - output: '''called deepCopy for int + output: ''' called deepCopy for int -done999 999''' +called deepCopy for int +done999 999 +''' """ import threadpool diff --git a/tests/parallel/tdisjoint_slice1.nim b/tests/parallel/tdisjoint_slice1.nim index c1d0e52f8..edcc30ece 100644 --- a/tests/parallel/tdisjoint_slice1.nim +++ b/tests/parallel/tdisjoint_slice1.nim @@ -2,20 +2,49 @@ discard """ outputsub: "EVEN 28" """ -import threadpool - -proc odd(a: int) = echo "ODD ", a -proc even(a: int) = echo "EVEN ", a - -proc main() = - var a: array[0..30, int] - for i in low(a)..high(a): a[i] = i - parallel: - var i = 0 - while i <= 29: - spawn even(a[i]) - spawn odd(a[i+1]) - inc i, 2 - # is correct here - -main() +import threadpool, locks + +block one: + proc odd(a: int) = echo "ODD ", a + proc even(a: int) = echo "EVEN ", a + + proc main() = + var a: array[0..30, int] + for i in low(a)..high(a): a[i] = i + parallel: + var i = 0 + while i <= 29: + spawn even(a[i]) + spawn odd(a[i+1]) + inc i, 2 + # is correct here + + main() + + +block two: + var echoLock: Lock + initLock echoLock + + proc f(a: openArray[int]) = + for x in a: + withLock echoLock: + echo x + + proc f(a: int) = + withLock echoLock: + echo a + + proc main() = + var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9] + parallel: + spawn f(a[0..2]) + #spawn f(a[16..30]) + var i = 3 + while i <= 8: + spawn f(a[i]) + spawn f(a[i+1]) + inc i, 2 + # is correct here + + main() diff --git a/tests/parallel/tdisjoint_slice2.nim b/tests/parallel/tdisjoint_slice2.nim deleted file mode 100644 index 25cb2362f..000000000 --- a/tests/parallel/tdisjoint_slice2.nim +++ /dev/null @@ -1,40 +0,0 @@ -discard """ - output: '''0 -1 -2 -3 -4 -5 -6 -7 -8''' - sortoutput: true -""" - -import threadpool, locks - -var echoLock: Lock -initLock echoLock - -proc f(a: openArray[int]) = - for x in a: - withLock echoLock: - echo x - -proc f(a: int) = - withLock echoLock: - echo a - -proc main() = - var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9] - parallel: - spawn f(a[0..2]) - #spawn f(a[16..30]) - var i = 3 - while i <= 8: - spawn f(a[i]) - spawn f(a[i+1]) - inc i, 2 - # is correct here - -main() diff --git a/tests/parallel/tmissing_deepcopy.nim b/tests/parallel/tmissing_deepcopy.nim index 94e027b60..7803439fa 100644 --- a/tests/parallel/tmissing_deepcopy.nim +++ b/tests/parallel/tmissing_deepcopy.nim @@ -26,10 +26,10 @@ proc greet(p:Person) = " friend:", p.friend.name, "(", cast[int](addr p.friend.name),") }" proc setup = - for i in 0 ..< 20: + for i in 0 ..< 10: people.add newPerson("Person" & $(i + 1)) - for i in 0 ..< 20: - people[i].friend = people[19-i] + for i in 0 ..< 10: + people[i].friend = people[9-i] proc update = parallel: diff --git a/tests/parallel/tsendtwice.nim b/tests/parallel/tsendtwice.nim index 0b3ce15a5..03b7fda47 100644 --- a/tests/parallel/tsendtwice.nim +++ b/tests/parallel/tsendtwice.nim @@ -17,9 +17,9 @@ import tables type Base* = ref object of RootObj someSeq: seq[int] - baseData: array[400000, byte] + baseData: array[40000, byte] Derived* = ref object of Base - data: array[400000, byte] + data: array[40000, byte] type ThreadPool = ref object diff --git a/tests/parallel/twaitany.nim b/tests/parallel/twaitany.nim index 2be3d432f..b58cadd86 100644 --- a/tests/parallel/twaitany.nim +++ b/tests/parallel/twaitany.nim @@ -3,7 +3,7 @@ discard """ """ # bug #7638 -import threadpool, os, strformat +import threadpool, os proc timer(d: int): int = #echo fmt"sleeping {d}" @@ -11,7 +11,7 @@ proc timer(d: int): int = #echo fmt"done {d}" return d -var durations = [1000, 1500, 2000, 2500, 3000] +var durations = [1000, 1500, 2000] var tasks: seq[FlowVarBase] = @[] var results: seq[int] = @[] @@ -25,11 +25,9 @@ while index != -1: #echo repr results index = blockUntilAny(tasks) -doAssert results.len == 5 +doAssert results.len == 3 doAssert 1000 in results doAssert 1500 in results doAssert 2000 in results -doAssert 2500 in results -doAssert 3000 in results sync() echo "true" |