mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
* done * Apply suggestions from code review * fixup Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
discard """
|
||||
targets: "c"
|
||||
matrix: "--gc:refc; --gc:arc; --gc:orc"
|
||||
target: "c"
|
||||
"""
|
||||
|
||||
import coro
|
||||
when compileOption("gc", "refc") or not defined(openbsd):
|
||||
# xxx openbsd gave: stdlib_coro.nim.c:406:22: error: array type 'jmp_buf' (aka 'long [11]') is not assignable (*dest).execContext = src.execContext;
|
||||
import coro
|
||||
|
||||
var maxOccupiedMemory = 0
|
||||
var maxOccupiedMemory = 0
|
||||
|
||||
proc testGC() =
|
||||
var numbers = newSeq[int](100)
|
||||
maxOccupiedMemory = max(maxOccupiedMemory, getOccupiedMem())
|
||||
suspend(0)
|
||||
proc testGC() =
|
||||
var numbers = newSeq[int](100)
|
||||
maxOccupiedMemory = max(maxOccupiedMemory, getOccupiedMem())
|
||||
suspend(0)
|
||||
|
||||
start(testGC)
|
||||
start(testGC)
|
||||
run()
|
||||
start(testGC)
|
||||
start(testGC)
|
||||
run()
|
||||
|
||||
GC_fullCollect()
|
||||
doAssert(getOccupiedMem() < maxOccupiedMemory, "GC did not free any memory allocated in coroutines")
|
||||
GC_fullCollect()
|
||||
doAssert(getOccupiedMem() < maxOccupiedMemory, "GC did not free any memory allocated in coroutines")
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
discard """
|
||||
output: "Exit 1\nExit 2"
|
||||
targets: "c"
|
||||
matrix: "--gc:refc; --gc:arc; --gc:orc"
|
||||
target: "c"
|
||||
"""
|
||||
import coro
|
||||
|
||||
var coro1: CoroutineRef
|
||||
when compileOption("gc", "refc") or not defined(openbsd):
|
||||
# xxx openbsd failed, see tgc.nim
|
||||
import coro
|
||||
|
||||
proc testCoroutine1() =
|
||||
for i in 0..<10:
|
||||
suspend(0)
|
||||
var coro1: CoroutineRef
|
||||
|
||||
proc testCoroutine1() =
|
||||
for i in 0..<10:
|
||||
suspend(0)
|
||||
echo "Exit 1"
|
||||
|
||||
proc testCoroutine2() =
|
||||
coro1.wait()
|
||||
echo "Exit 2"
|
||||
|
||||
coro1 = coro.start(testCoroutine1)
|
||||
coro.start(testCoroutine2)
|
||||
run()
|
||||
else:
|
||||
# workaround
|
||||
echo "Exit 1"
|
||||
|
||||
proc testCoroutine2() =
|
||||
coro1.wait()
|
||||
echo "Exit 2"
|
||||
|
||||
coro1 = coro.start(testCoroutine1)
|
||||
coro.start(testCoroutine2)
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user