mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 03:36:34 +02:00
Added exapmle program
This commit is contained in:
parent
2e60569dd0
commit
f0cf1f34f0
1 changed files with 26 additions and 0 deletions
26
libs/cyclone/use-shared-queue.scm
Normal file
26
libs/cyclone/use-shared-queue.scm
Normal 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")
|
Loading…
Add table
Reference in a new issue