Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmacro with-unlocked-box ((value box) &body body)
- "An attempt at some sort of thread safety trick. The idea is that we
- can only write to the locked value inside this macro body. It might work.
- Maybe.
- (defvar *box* (make-locked-box :value 42))
- (with-thread (:name \"Evil fighting thread!\")
- (loop
- (setf v :woohoo-type-error-time)
- (sleep 0.01)))
- (with-unlocked-box (v *box*)
- (setf v 12300)
- (+ v 45)) ; => 12345 (always)
- "
- (alexandria:once-only (box)
- `(bt:with-lock-held ((locked-box-lock ,box))
- (symbol-macrolet ((,value (locked-box-value ,box)))
- . ,body))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement