Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Open
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
27 changes: 26 additions & 1 deletion tests/basic.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
;;;;

(define-module (tests basic)
#:use-module (fibers))
#:use-module (fibers)
#:use-module (srfi srfi-1))

(define failed? #f)

Expand Down Expand Up @@ -96,6 +97,30 @@

;; sleep wakeup order

(define sleep-list-mtx (make-mutex))

(define sleep-list '())

(define (add-order n)
(lock-mutex sleep-list-mtx)
(set! sleep-list (cons n sleep-list))
(unlock-mutex sleep-list-mtx))

(define *randstate* (random-state-from-platform))

;; TODO(codemac): Curerntly this does not pass, as the "spawn time"
;; for each sleep isn't actually taken into account here. Ideally we
;; can make these sleeps small enough that the test goes quickly
;; without actually drifting across when each spawn-fiber is called.
(assert-run-fibers-terminates
(do-times
1000
(let* ((nr (random 100 *randstate*))
(n (exact->inexact (/ nr 1000))))
(spawn-fiber (lambda () (sleep n) (add-order n))))))

(assert-equal (sort sleep-list <) (reverse sleep-list))

;; fib using channels

;; sleep durations
Expand Down