This commit is contained in:
Justin Ethier 2019-06-26 19:01:34 -04:00
parent f0cf1f34f0
commit 4dafbd7984
2 changed files with 16 additions and 3 deletions

View file

@ -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))

View file

@ -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)