Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put std/threads under the umbrella of nimPreviewSlimSystem #20711

Merged
merged 5 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/concurrency/threadpool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}

Expand Down
2 changes: 1 addition & 1 deletion lib/pure/random.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}
Expand Down
10 changes: 0 additions & 10 deletions lib/std/threads.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
7 changes: 4 additions & 3 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions lib/system/threadimpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions nimsuggest/nimsuggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/arc/tweave.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ discard """

import std/atomics

when defined(nimPreviewSlimSystem):
import std/[assertions, threads]

const MemBlockSize = 256

type
Expand Down
5 changes: 4 additions & 1 deletion tests/stdlib/tenvvars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/tnetdial.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ discard """
"""

import os, net, nativesockets, asyncdispatch
import std/[assertions]
import std/[assertions, threads]

## Test for net.dial

Expand Down
6 changes: 5 additions & 1 deletion tests/stdlib/tosenv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/tssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/threads/t7172.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Crashes before getting here!
"""

import std/os
import std/threads

proc whatever() {.thread, nimcall.} =
echo("TEST")
Expand Down