diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 5953ed9758..08fa60dbce 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -167,7 +167,7 @@ export asyncstreams type PDispatcherBase = ref object of RootRef timers*: HeapQueue[tuple[finishAt: float, fut: Future[void]]] - callbacks*: Deque[proc ()] + callbacks*: Deque[proc () {.gcsafe.}] proc processTimers( p: PDispatcherBase, didSomeWork: var bool @@ -200,7 +200,9 @@ proc adjustTimeout(pollTimeout: int, nextTimer: Option[int]): int {.inline.} = if pollTimeout == -1: return result = min(pollTimeout, result) -proc callSoon*(cbproc: proc ()) {.gcsafe.} +proc callSoon*(cbproc: proc () {.gcsafe.}) {.gcsafe.} + ## Schedule `cbproc` to be called as soon as possible. + ## The callback is called when control returns to the event loop. proc initCallSoonProc = if asyncfutures.getCallSoonProc().isNil: @@ -1806,9 +1808,7 @@ proc readAll*(future: FutureStream[string]): Future[string] {.async.} = else: break -proc callSoon*(cbproc: proc ()) = - ## Schedule `cbproc` to be called as soon as possible. - ## The callback is called when control returns to the event loop. +proc callSoon(cbproc: proc () {.gcsafe.}) = getGlobalDispatcher().callbacks.addLast(cbproc) proc runForever*() = diff --git a/tests/threads/t8535.nim b/tests/threads/t8535.nim index e1b5a13692..dfc95547d1 100644 --- a/tests/threads/t8535.nim +++ b/tests/threads/t8535.nim @@ -1,16 +1,29 @@ discard """ - output: "0" + output: '''0 +hello''' """ type - CircAlloc* [Size: static[int] , T] = tuple - baseArray : array[Size,T] - index : uint16 + CircAlloc*[Size: static[int], T] = tuple + baseArray: array[Size,T] + index: uint16 type Job = object of RootObj -var foo {.threadvar.}: CircAlloc[1,Job] +var foo {.threadvar.}: CircAlloc[1, Job] when true: echo foo.index + + +# bug #10795 +import asyncdispatch +import threadpool + +proc f1() = + waitFor sleepAsync(100) + echo "hello" + +spawn f1() +sync()