Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.60 KB | None | 0 0
  1. (defmacro with-unlocked-box ((value box) &body body)
  2.   "An attempt at some sort of thread safety trick. The idea is that we
  3. can only write to the locked value inside this macro body. It might work.
  4. Maybe.
  5.  
  6. (defvar *box* (make-locked-box :value 42))
  7.  
  8. (with-thread (:name \"Evil fighting thread!\")
  9.  (loop
  10.   (setf v :woohoo-type-error-time)
  11.   (sleep 0.01)))
  12.  
  13. (with-unlocked-box (v *box*)
  14.  (setf v 12300)
  15.  (+ v 45)) ; => 12345 (always)
  16. "
  17.   (alexandria:once-only (box)
  18.     `(bt:with-lock-held ((locked-box-lock ,box))
  19.        (symbol-macrolet ((,value (locked-box-value ,box)))
  20.          . ,body))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement