summary refs log tree commit diff stats
path: root/tests/threads
diff options
context:
space:
mode:
Diffstat (limited to 'tests/threads')
-rw-r--r--tests/threads/t7172.nim34
-rw-r--r--tests/threads/t8535.nim3
-rw-r--r--tests/threads/threadex.nim1
-rw-r--r--tests/threads/tjsthreads.nim6
-rw-r--r--tests/threads/tmanyjoin.nim3
-rw-r--r--tests/threads/tmembug.nim51
-rw-r--r--tests/threads/tonthreadcreation.nim2
-rw-r--r--tests/threads/tracy_allocator.nim1
-rw-r--r--tests/threads/treusetvar.nim7
-rw-r--r--tests/threads/tthreadanalysis2.nim51
-rw-r--r--tests/threads/tthreadvars.nim1
-rw-r--r--tests/threads/ttryrecv.nim3
12 files changed, 106 insertions, 57 deletions
diff --git a/tests/threads/t7172.nim b/tests/threads/t7172.nim
new file mode 100644
index 000000000..87e89417b
--- /dev/null
+++ b/tests/threads/t7172.nim
@@ -0,0 +1,34 @@
+discard """
+  disabled: i386
+  output: '''
+In doStuff()
+In initProcess()
+TEST
+initProcess() done
+Crashes before getting here!
+'''
+  joinable: false
+"""
+
+import std/os
+import std/typedthreads
+
+proc whatever() {.thread, nimcall.} =
+  echo("TEST")
+
+proc initProcess(): void =
+  echo("In initProcess()")
+  var thread: Thread[void]
+  createThread(thread, whatever)
+  joinThread(thread)
+  echo("initProcess() done")
+
+proc doStuff(): void =
+  echo("In doStuff()")
+  # ...
+  initProcess()
+  sleep(500)
+  # ...
+  echo("Crashes before getting here!")
+
+doStuff()
diff --git a/tests/threads/t8535.nim b/tests/threads/t8535.nim
index dfc95547d..a4296df11 100644
--- a/tests/threads/t8535.nim
+++ b/tests/threads/t8535.nim
@@ -1,4 +1,5 @@
 discard """
+  disabled: i386
   output: '''0
 hello'''
 """
@@ -22,7 +23,7 @@ import asyncdispatch
 import threadpool
 
 proc f1() =
-  waitFor sleepAsync(100)
+  waitFor sleepAsync(20)
   echo "hello"
 
 spawn f1()
diff --git a/tests/threads/threadex.nim b/tests/threads/threadex.nim
index 50a1a4d34..90119aee7 100644
--- a/tests/threads/threadex.nim
+++ b/tests/threads/threadex.nim
@@ -1,4 +1,5 @@
 discard """
+  disabled: i386
   outputsub: "Just a simple text for test"
 """
 
diff --git a/tests/threads/tjsthreads.nim b/tests/threads/tjsthreads.nim
new file mode 100644
index 000000000..5122c9cd6
--- /dev/null
+++ b/tests/threads/tjsthreads.nim
@@ -0,0 +1,6 @@
+discard """
+  targets: "js"
+  matrix: "--threads:on"
+"""
+
+echo 123
diff --git a/tests/threads/tmanyjoin.nim b/tests/threads/tmanyjoin.nim
index 2c1cda494..af5bc460e 100644
--- a/tests/threads/tmanyjoin.nim
+++ b/tests/threads/tmanyjoin.nim
@@ -1,4 +1,5 @@
 discard """
+  disabled: i386
   outputsub: "129"
 """
 
@@ -12,7 +13,7 @@ type
 
 const
   ThreadsCount = 129
-  SleepTime = 1000
+  SleepTime = 250
 
 proc worker(p: Marker) {.thread.} =
   acquire(p.lock)
diff --git a/tests/threads/tmembug.nim b/tests/threads/tmembug.nim
new file mode 100644
index 000000000..3618f0ecc
--- /dev/null
+++ b/tests/threads/tmembug.nim
@@ -0,0 +1,51 @@
+
+import std / [atomics, strutils, sequtils]
+
+type
+  BackendMessage* = object
+    field*: seq[int]
+
+var
+  chan1: Channel[BackendMessage]
+  chan2: Channel[BackendMessage]
+
+chan1.open()
+chan2.open()
+
+proc routeMessage*(msg: BackendMessage) =
+  discard chan2.trySend(msg)
+
+var
+  recv: Thread[void]
+  stopToken: Atomic[bool]
+
+proc recvMsg() =
+  while not stopToken.load(moRelaxed):
+    let resp = chan1.tryRecv()
+    if resp.dataAvailable:
+      routeMessage(resp.msg)
+      echo "child consumes ", formatSize getOccupiedMem()
+
+createThread[void](recv, recvMsg)
+
+const MESSAGE_COUNT = 100
+
+proc main() =
+  let msg: BackendMessage = BackendMessage(field: (0..500).toSeq())
+  for j in 0..0: #100:
+    echo "New iteration"
+
+    for _ in 1..MESSAGE_COUNT:
+      chan1.send(msg)
+    echo "After sending"
+
+    var counter = 0
+    while counter < MESSAGE_COUNT:
+      let resp = recv(chan2)
+      counter.inc
+    echo "After receiving ", formatSize getOccupiedMem()
+
+  stopToken.store true, moRelaxed
+  joinThreads(recv)
+
+main()
diff --git a/tests/threads/tonthreadcreation.nim b/tests/threads/tonthreadcreation.nim
index f588a21c9..61529477d 100644
--- a/tests/threads/tonthreadcreation.nim
+++ b/tests/threads/tonthreadcreation.nim
@@ -1,4 +1,6 @@
 discard """
+  disabled: i386
+  matrix: "--mm:refc; --mm:orc --deepcopy:on"
   output: '''some string here
 dying some string here'''
 """
diff --git a/tests/threads/tracy_allocator.nim b/tests/threads/tracy_allocator.nim
index e8f0ec927..f3b39f4dc 100644
--- a/tests/threads/tracy_allocator.nim
+++ b/tests/threads/tracy_allocator.nim
@@ -1,4 +1,5 @@
 discard """
+  disabled: i386
   output: '''true'''
 """
 
diff --git a/tests/threads/treusetvar.nim b/tests/threads/treusetvar.nim
index 672da6bdd..f0337801a 100644
--- a/tests/threads/treusetvar.nim
+++ b/tests/threads/treusetvar.nim
@@ -1,8 +1,9 @@
 discard """
-  outputsub: "129"
+  disabled: i386
+  outputsub: "65"
 """
 
-import os, locks
+import locks
 
 type
   MarkerObj = object
@@ -11,7 +12,7 @@ type
   Marker = ptr MarkerObj
 
 const
-  ThreadsCount = 129
+  ThreadsCount = 65
 
 proc worker(p: Marker) {.thread.} =
   acquire(p.lock)
diff --git a/tests/threads/tthreadanalysis2.nim b/tests/threads/tthreadanalysis2.nim
deleted file mode 100644
index 067e186a8..000000000
--- a/tests/threads/tthreadanalysis2.nim
+++ /dev/null
@@ -1,51 +0,0 @@
-discard """
-  errormsg: "'threadFunc' is not GC-safe"
-  file: "tthreadanalysis2.nim"
-  line: 37
-  cmd: "nim $target --hints:on --threads:on $options $file"
-"""
-
-import os
-
-var
-  thr: array[0..5, Thread[tuple[a, b: int]]]
-
-proc doNothing() = discard
-
-type
-  PNode = ref TNode
-  TNode = object {.pure.}
-    le, ri: PNode
-    data: string
-
-var
-  root: PNode
-
-proc buildTree(depth: int): PNode =
-  if depth == 3: return nil
-  new(result)
-  result.le = buildTree(depth-1)
-  result.ri = buildTree(depth-1)
-  result.data = $depth
-
-proc echoLeTree(n: PNode) =
-  var it = n
-  while it != nil:
-    echo it.data
-    it = it.le
-
-proc threadFunc(interval: tuple[a, b: int]) {.thread.} =
-  doNothing()
-  for i in interval.a..interval.b:
-    var r = buildTree(i)
-    echoLeTree(r) # for local data
-  root = buildTree(2) # BAD!
-  #echoLeTree(root) # and the same for foreign data :-)
-
-proc main =
-  root = buildTree(5)
-  for i in 0..high(thr):
-    createThread(thr[i], threadFunc, (i*100, i*100+50))
-  joinThreads(thr)
-
-main()
diff --git a/tests/threads/tthreadvars.nim b/tests/threads/tthreadvars.nim
index 81aa2e5ec..745e3562c 100644
--- a/tests/threads/tthreadvars.nim
+++ b/tests/threads/tthreadvars.nim
@@ -1,4 +1,5 @@
 discard """
+disabled: i386
 output: '''
 10
 1111
diff --git a/tests/threads/ttryrecv.nim b/tests/threads/ttryrecv.nim
index 87dec6e79..fcff94e78 100644
--- a/tests/threads/ttryrecv.nim
+++ b/tests/threads/ttryrecv.nim
@@ -1,4 +1,5 @@
 discard """
+  matrix: "--mm:refc"
   outputsub: "channel is empty"
 """
 
@@ -11,7 +12,7 @@ type PComm = ptr Channel[int]
 
 proc doAction(outC: PComm) {.thread.} =
   for i in 0 ..< 5:
-    sleep(rand(100))
+    sleep(rand(50))
     send(outC[], i)
 
 var