[Openmcl-devel] Improving bordeaux-threads on CCL

James M. Lawrence llmjjmll at gmail.com
Sun Sep 8 15:32:18 PDT 2013


Is ccl:wait-on-semaphore interrupt-safe? If it is then my next
question relates to making bordeaux-threads safer. It may be that
condition variables cannot be perfectly implemented with semaphores,
but the current situation may at least be improvable. The
bordeaux-threads code is basically

(defun make-condition-variable ()
  (ccl:make-semaphore))

(defun condition-notify (condition-variable)
  (ccl:signal-semaphore condition-variable))

(defun condition-wait (condition-variable lock)
  (ccl:release-lock lock)
  (unwind-protect
       (ccl:wait-on-semaphore condition-variable)
    (ccl:grab-lock lock t)))

A safe version of condition-wait might be

(defun condition-wait (condition-variable lock)
  (ccl:without-interrupts
    (ccl:release-lock lock)
    (unwind-protect
         (ccl:with-interrupts-enabled
           (ccl:wait-on-semaphore condition-variable))
      (ccl:grab-lock lock))))

However the grab-lock has the potential of causing an unkillable
deadlock, and there may be other issues.

Interrupting threads is generally bad news because Lisp code is not
generally expected to be interrupt-safe. But in the context of limited
guarantees on particular data structures, an interrupt-safe
condition-wait would be useful. It could be that such data structures
on CCL must be written without the condition-variable emulation.



More information about the Openmcl-devel mailing list