Skip to content

Instantly share code, notes, and snippets.

@informatimago
Created September 21, 2018 17:24
Show Gist options
  • Save informatimago/7b874fbbfcb759ce2a1c1ca484728b40 to your computer and use it in GitHub Desktop.
Save informatimago/7b874fbbfcb759ce2a1c1ca484728b40 to your computer and use it in GitHub Desktop.
;; https://www.axess-industries.com/casiers-consignes/armoire-casier-a-effet-personnel-p-150576-600x600.jpg
;; casier: a box protected by a lock!
(terpri) (ql:quickload :bordeaux-threads)
(defstruct casier
value
(lock (bt:make-lock)))
(defun (setf casier) (new-value casier)
(bt:with-lock-held ((casier-lock casier))
(setf (casier-value casier) new-value)))
(defun casier (casier)
(bt:with-lock-held ((casier-lock casier))
(casier-value casier)))
(defparameter *stop-worker-thread* (make-casier))
(bt:make-thread (lambda ()
(loop
:do (sleep 0.1)
(princ "+")
(finish-output)
:until (casier *stop-worker-thread*)))
:initial-bindings `((*standard-output* . ,*terminal-io*))
:name "Test Casier")
(sleep 10)
(setf (casier *stop-worker-thread*) t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment