Skip to content

Commit

Permalink
follow up nim-lang#17391 add testcase (nim-lang#17404)
Browse files Browse the repository at this point in the history
* Revert "make system random work in VM"

* fix nim-lang#17380

* attempt to fix bug

* fix

* better

* fix

* a bit

* fix the leaks

* revert

* fix

* better

* follow up nim-lang#17391

* fix

* Update tchannels.nim

* Update tests/stdlib/tchannels.nim

* Update tchannels.nim
  • Loading branch information
ringabout committed Mar 22, 2021
1 parent eddff33 commit 35fcb0a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/stdlib/tchannels.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
discard """
timeout: 5.0 # but typically < 1s
disabled: "freebsd"
matrix: "--gc:arc --threads:on; --gc:arc --threads:on -d:danger"
"""

when true:
# bug #17380: this was either blocking (without -d:danger) or crashing with SIGSEGV (with -d:danger)
import std/[channels, isolation]
const
N1 = 10
N2 = 100
var
sender: array[N1, Thread[void]]
receiver: array[5, Thread[void]]

var chan = newChannel[seq[string]](N1 * N2) # large enough to not block
proc sendHandler() =
chan.send(isolate(@["Hello, Nim"]))
proc recvHandler() =
template fn =
let x = chan.recv()
fn()

template benchmark() =
for t in mitems(sender):
t.createThread(sendHandler)
joinThreads(sender)
for t in mitems(receiver):
t.createThread(recvHandler)
joinThreads(receiver)
for i in 0..<N2:
benchmark()

0 comments on commit 35fcb0a

Please sign in to comment.