mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-20 22:29:16 +02:00
WIP
This commit is contained in:
parent
8a0bb68eba
commit
fd77b7936c
1 changed files with 39 additions and 0 deletions
|
@ -3,3 +3,42 @@
|
||||||
; a consumer reading from it
|
; a consumer reading from it
|
||||||
; an important consideration is how to let the producers write values, since they would be on their stacks!
|
; an important consideration is how to let the producers write values, since they would be on their stacks!
|
||||||
; ideally do not want the application to have to worry about what value came from what thread...
|
; ideally do not want the application to have to worry about what value came from what thread...
|
||||||
|
|
||||||
|
(import
|
||||||
|
(scheme base)
|
||||||
|
(scheme read)
|
||||||
|
(scheme write)
|
||||||
|
(srfi 18))
|
||||||
|
|
||||||
|
|
||||||
|
(define *lock* (make-mutex))
|
||||||
|
(define *queue* (list))
|
||||||
|
|
||||||
|
(define (producer)
|
||||||
|
(let loop ((n 10))
|
||||||
|
(cond
|
||||||
|
((> n 0)
|
||||||
|
(mutex-lock! *lock*)
|
||||||
|
(set! *queue* (cons n *queue*))
|
||||||
|
(mutex-unlock! *lock*)
|
||||||
|
(loop (- n 1))))))
|
||||||
|
|
||||||
|
(define (consumer)
|
||||||
|
(let loop ()
|
||||||
|
(write (list (null? *queue*) *queue*))
|
||||||
|
(define sleep? #f)
|
||||||
|
(mutex-lock! *lock*)`
|
||||||
|
(cond
|
||||||
|
((not (null? *queue*))
|
||||||
|
(write (car *queue*))
|
||||||
|
(set! *queue* (cdr *queue*)))
|
||||||
|
(else
|
||||||
|
(set! sleep? #t)))
|
||||||
|
(mutex-unlock! *lock*)
|
||||||
|
(if sleep? (thread-sleep! 1000))
|
||||||
|
(loop)))
|
||||||
|
|
||||||
|
(thread-start! (make-thread producer))
|
||||||
|
(producer)
|
||||||
|
(consumer)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue