Need CAS2
Hi, While the need for CAS2 doesn’t arise very often, as long as we have CAS implemented, and with today’s processors already supporting CAS2, why not go ahead and offer it as well? CAS2 would also help with some STM implementations. I ended up inventing my own, but a kernel built-in would doubtless be more efficient. Here is my own solution, done with a spin-lock: (defun spin-lock (atomic-ref) (loop until (cas atomic-ref nil t))) (defmacro with-spin-lock (atomic-ref &body body) ;; interrupts should be disabled before calling this `(spin-lock ,atomic-ref) (unwind-protect (progn ,@body) (setf ,atomic-ref nil))) )) ;; this should be generalized… too specific here (defvar *polling-spinlock* nil) (defun CAS2 (comm1 bev1 comm2 bev2) ;; interrupts should be disabled before calling this (with-spin-lock *polling-spinlock* (and (CAS comm1 nil bev1) (or (CAS comm2 nil bev2) (setf comm1 nil))) )) - DM _______________________________________________ Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com http://www.lispworks.com/support/lisp-hug.html