cyclone/examples/threading/parameters.scm
Justin Ethier dbe8597e90 Cleanup
2017-03-14 21:14:01 +00:00

31 lines
804 B
Scheme

;; A simple program demonstrating how parameter objects interact with threads
;;
;; Note this is poor code as it uses timing via sleeps instead of proper
;; thread synchronization!!!
;;
(import (scheme base)
(scheme read)
(scheme write)
(srfi 18)
)
(thread-start!
(make-thread
(lambda ()
(thread-sleep! 1200)
(display "started thread, this should be written to console")
(newline)
(display "thread done")
(newline)
(flush-output-port (current-output-port)))))
(thread-sleep! 1000) ;; Prevent race condition replacing stdout before thread is spawned
(write `(1 2 3))
(define fp (open-output-file "tmp.txt"))
(parameterize
((current-output-port fp))
(write `(4 5 6))
(thread-sleep! 3000)
)
(close-port fp)
(write `(7 8 9))