Skip to content

Instantly share code, notes, and snippets.

@nkoguro
Created May 30, 2020 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkoguro/7fd58e919c0ae0050280e874ab22ddf2 to your computer and use it in GitHub Desktop.
Save nkoguro/7fd58e919c0ae0050280e874ab22ddf2 to your computer and use it in GitHub Desktop.
(use data.queue)
(use gauche.partcont)
(define queue (make-queue))
(define (wrap thunk)
(lambda ()
;; Add guard here!!
(guard (e (else (raise e)))
(reset
(thunk)))))
(define (yield)
(shift cont
(enqueue! queue (wrap cont))))
(define (main args)
(enqueue! queue (wrap (lambda ()
(let1 counter 0
(while #t
(inc! counter)
(when (= counter 100000)
(set! counter 0)
(format #t "~s~%" (gc-stat)))
(yield))))))
(while #t
(let1 next (dequeue! queue #f)
(when next
(next))))
0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment