summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-31 13:36:50 +0800
committerGitHub <noreply@github.com>2022-10-31 06:36:50 +0100
commite1ddd2d524e3e57df25d6498d275f019e450111e (patch)
tree9d531ffc00e74da2569977b792a8b3304f25c919
parentfb2ec8d192cbaa36868f28275993936868ba2d31 (diff)
downloadNim-e1ddd2d524e3e57df25d6498d275f019e450111e.tar.gz
put std/threads under the umbrella of nimPreviewSlimSystem (#20711)
* put `std/threads` under the umbrella of `nimPreviewSlimSystem`

* add changelog

* fixes tests

* fixes tests again

* fixes tests
-rw-r--r--changelog.md1
-rw-r--r--lib/pure/concurrency/threadpool.nim2
-rw-r--r--lib/pure/random.nim2
-rw-r--r--lib/std/threads.nim10
-rw-r--r--lib/system.nim7
-rw-r--r--lib/system/threadimpl.nim9
-rw-r--r--nimsuggest/nimsuggest.nim2
-rw-r--r--tests/arc/tweave.nim3
-rw-r--r--tests/stdlib/tenvvars.nim5
-rw-r--r--tests/stdlib/tnetdial.nim2
-rw-r--r--tests/stdlib/tosenv.nim6
-rw-r--r--tests/stdlib/tssl.nim2
-rw-r--r--tests/threads/t7172.nim1
13 files changed, 33 insertions, 19 deletions
diff --git a/changelog.md b/changelog.md
index 72b518bb8..4d24d73c0 100644
--- a/changelog.md
+++ b/changelog.md
@@ -15,6 +15,7 @@
   - `std/formatfloat`
   - `std/objectdollar`
   - `std/widestrs`
+  - `std/threads`
 
   In the future, these definitions will be removed from the `system` module,
   and their respective modules will have to be imported to use them.
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index 5d9e7452b..50f3be1ea 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -24,7 +24,7 @@ when not compileOption("threads"):
 import cpuinfo, cpuload, locks, os
 
 when defined(nimPreviewSlimSystem):
-  import std/assertions
+  import std/[assertions, threads]
 
 {.push stackTrace:off.}
 
diff --git a/lib/pure/random.nim b/lib/pure/random.nim
index de93f468f..9418924da 100644
--- a/lib/pure/random.nim
+++ b/lib/pure/random.nim
@@ -76,7 +76,7 @@ import algorithm, math
 import std/private/since
 
 when defined(nimPreviewSlimSystem):
-  import std/assertions
+  import std/[assertions]
 
 include system/inclrtl
 {.push debugger: off.}
diff --git a/lib/std/threads.nim b/lib/std/threads.nim
index 5726a5cdc..358ff0d9e 100644
--- a/lib/std/threads.nim
+++ b/lib/std/threads.nim
@@ -95,16 +95,6 @@ when defined(zephyr):
 
 
 
-proc onThreadDestruction*(handler: proc () {.closure, gcsafe, raises: [].}) =
-  ## Registers a *thread local* handler that is called at the thread's
-  ## destruction.
-  ##
-  ## A thread is destructed when the `.thread` proc returns
-  ## normally or when it raises an exception. Note that unhandled exceptions
-  ## in a thread nevertheless cause the whole process to die.
-  nimThreadDestructionHandlers.add handler
-
-
 {.push stack_trace:off.}
 when defined(windows):
   proc threadProcWrapper[TArg](closure: pointer): int32 {.stdcall.} =
diff --git a/lib/system.nim b/lib/system.nim
index ff2bff45f..68645cea0 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2093,9 +2093,10 @@ when not defined(js):
   when hasThreadSupport:
     when hostOS != "standalone":
       include system/threadimpl
-
-      import std/threads
-      export threads
+      when not defined(nimPreviewSlimSystem):
+        {.deprecated: "threads is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/threads`".}
+        import std/threads
+        export threads
 
   elif not defined(nogc) and not defined(nimscript):
     when not defined(useNimRtl) and not defined(createNimRtl): initStackBottom()
diff --git a/lib/system/threadimpl.nim b/lib/system/threadimpl.nim
index 73f2807d2..94db23336 100644
--- a/lib/system/threadimpl.nim
+++ b/lib/system/threadimpl.nim
@@ -33,6 +33,15 @@ template afterThreadRuns() =
   for i in countdown(nimThreadDestructionHandlers.len-1, 0):
     nimThreadDestructionHandlers[i]()
 
+proc onThreadDestruction*(handler: proc () {.closure, gcsafe, raises: [].}) =
+  ## Registers a *thread local* handler that is called at the thread's
+  ## destruction.
+  ##
+  ## A thread is destructed when the `.thread` proc returns
+  ## normally or when it raises an exception. Note that unhandled exceptions
+  ## in a thread nevertheless cause the whole process to die.
+  nimThreadDestructionHandlers.add handler
+
 when defined(boehmgc):
   type GCStackBaseProc = proc(sb: pointer, t: pointer) {.noconv.}
   proc boehmGC_call_with_stack_base(sbp: GCStackBaseProc, p: pointer)
diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim
index d4c0f7545..3b2615891 100644
--- a/nimsuggest/nimsuggest.nim
+++ b/nimsuggest/nimsuggest.nim
@@ -29,6 +29,8 @@ import compiler / [options, commands, modules, sem,
   idents, modulegraphs, prefixmatches, lineinfos, cmdlinehelper,
   pathutils]
 
+when defined(nimPreviewSlimSystem):
+  import std/threads
 
 when defined(windows):
   import winlean
diff --git a/tests/arc/tweave.nim b/tests/arc/tweave.nim
index 220d65f97..fc576f484 100644
--- a/tests/arc/tweave.nim
+++ b/tests/arc/tweave.nim
@@ -8,6 +8,9 @@ discard """
 
 import std/atomics
 
+when defined(nimPreviewSlimSystem):
+  import std/[assertions, threads]
+
 const MemBlockSize = 256
 
 type
diff --git a/tests/stdlib/tenvvars.nim b/tests/stdlib/tenvvars.nim
index f09dd0965..e49bd519a 100644
--- a/tests/stdlib/tenvvars.nim
+++ b/tests/stdlib/tenvvars.nim
@@ -7,7 +7,10 @@ discard """
 import std/envvars
 from std/sequtils import toSeq
 import stdtest/testutils
-import std/assertions
+import std/[assertions]
+
+when not defined(js):
+  import std/threads
 
 # "LATIN CAPITAL LETTER AE" in UTF-8 (0xc386)
 const unicodeUtf8 = "\xc3\x86"
diff --git a/tests/stdlib/tnetdial.nim b/tests/stdlib/tnetdial.nim
index 3b8276d6f..41485d525 100644
--- a/tests/stdlib/tnetdial.nim
+++ b/tests/stdlib/tnetdial.nim
@@ -5,7 +5,7 @@ discard """
 """
 
 import os, net, nativesockets, asyncdispatch
-import std/[assertions]
+import std/[assertions, threads]
 
 ## Test for net.dial
 
diff --git a/tests/stdlib/tosenv.nim b/tests/stdlib/tosenv.nim
index 365edc8c2..f715b4b70 100644
--- a/tests/stdlib/tosenv.nim
+++ b/tests/stdlib/tosenv.nim
@@ -7,7 +7,9 @@ discard """
 import std/os
 from std/sequtils import toSeq
 import stdtest/testutils
-import std/assertions
+
+when defined(nimPreviewSlimSystem):
+  import std/[assertions]
 
 # "LATIN CAPITAL LETTER AE" in UTF-8 (0xc386)
 const unicodeUtf8 = "\xc3\x86"
@@ -55,6 +57,8 @@ when defined(windows):
 proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "<stdlib.h>".}
 
 when not defined(js) and not defined(nimscript):
+  when defined(nimPreviewSlimSystem):
+    import std/threads
   block: # bug #18533
     var thr: Thread[void]
     proc threadFunc {.thread.} = putEnv("foo", "fooVal2")
diff --git a/tests/stdlib/tssl.nim b/tests/stdlib/tssl.nim
index 6d238e6c9..e4c6f68cf 100644
--- a/tests/stdlib/tssl.nim
+++ b/tests/stdlib/tssl.nim
@@ -4,7 +4,7 @@ discard """
   disabled: "openbsd"
 """
 # disabled: pending bug #15713
-import std/[net, nativesockets, assertions]
+import std/[net, nativesockets, assertions, threads]
 
 when defined(posix): import os, posix
 else:
diff --git a/tests/threads/t7172.nim b/tests/threads/t7172.nim
index 18fbe336e..127ed456e 100644
--- a/tests/threads/t7172.nim
+++ b/tests/threads/t7172.nim
@@ -10,6 +10,7 @@ Crashes before getting here!
 """
 
 import std/os
+import std/threads
 
 proc whatever() {.thread, nimcall.} =
   echo("TEST")