mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP
This commit is contained in:
parent
f0cf1f34f0
commit
4dafbd7984
2 changed files with 16 additions and 3 deletions
|
@ -114,6 +114,9 @@
|
|||
(loop (+ i 1) (inc start (vector-length old-store))))))
|
||||
)
|
||||
|
||||
;; Blocks if queue is empty (!)
|
||||
;; should we have a failsafe if the same thread that is doing adds, then
|
||||
;; does a blocking remove??
|
||||
(define (queue-remove! q)
|
||||
(let loop ()
|
||||
(mutex-lock! (q:lock q))
|
||||
|
|
|
@ -8,9 +8,16 @@
|
|||
|
||||
(define q (make-queue))
|
||||
(define (consume)
|
||||
(%consume)
|
||||
(%consume))
|
||||
(define (%consume)
|
||||
(let ((val (queue-remove! q)))
|
||||
(write `(removed ,val))
|
||||
(thread-sleep! 2)))
|
||||
(if (procedure? val)
|
||||
(set! val (val)))
|
||||
(write `(removed ,val ,(current-thread)))
|
||||
(newline)
|
||||
(thread-sleep! 1))
|
||||
)
|
||||
(define t1 (make-thread consume))
|
||||
(define t2 (make-thread consume))
|
||||
|
||||
|
@ -19,7 +26,10 @@
|
|||
|
||||
(thread-sleep! 1)
|
||||
(queue-add! q 'a)
|
||||
(queue-add! q 'b)
|
||||
(queue-add! q (lambda () (+ 1 2 3)))
|
||||
(queue-add! q 'c)
|
||||
(queue-add! q 'd)
|
||||
(queue-add! q 'e)
|
||||
|
||||
(thread-join! t1)
|
||||
(thread-join! t2)
|
||||
|
|
Loading…
Add table
Reference in a new issue