Skip to content

Commit

Permalink
add yield test
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Jul 22, 2020
1 parent 1511c67 commit 7902b09
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/tyield.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import std/os

import cps
import cps/eventqueue

const
start = 2
tiny = 0
big = start * 2
var count = start

proc higher(ms: int): Cont {.cps.} =
while count < big and count > tiny:
inc count
cps_sleep ms
cps_yield()
cps_yield()
cps_yield()

proc lower(ms: int): Cont {.cps.} =
while count < big and count > tiny:
dec count
cps_sleep ms
cps_yield()

trampoline higher(1)
trampoline lower(1)

run()

assert count == tiny
5 changes: 5 additions & 0 deletions tests/tyield.nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--path="$config/.."
--threads:on
--define:threadsafe
--gc:arc
--define:cpsDebug

0 comments on commit 7902b09

Please sign in to comment.