Added exapmle program

This commit is contained in:
Justin Ethier 2019-06-26 18:53:36 -04:00
parent 2e60569dd0
commit f0cf1f34f0

View file

@ -0,0 +1,26 @@
;; Example of multiple threads using a shared queue
(import
(scheme base)
(scheme write)
(shared-queue)
(srfi 18)
(cyclone concurrent))
(define q (make-queue))
(define (consume)
(let ((val (queue-remove! q)))
(write `(removed ,val))
(thread-sleep! 2)))
(define t1 (make-thread consume))
(define t2 (make-thread consume))
(thread-start! t1)
(thread-start! t2)
(thread-sleep! 1)
(queue-add! q 'a)
(queue-add! q 'b)
(thread-join! t1)
(thread-join! t2)
(write "done")