[slime-devel] Re: Use of with-lock inside without-interrupts
heller at common-lisp.net
Tue Aug 5 20:51:05 UTC 2008
* Martin Simmons [2008-08-05 21:26+0200] writes:
> I see some new changes in swank-lispworks.lisp where mp:with-lock is used
> inside mp:without-interrupts. What is the purpose of that?
My reasoning with this code was:
(lambda () (some test (mailbox.queue mbox))))
(mp:with-lock (lock "receive-if/try" 0.1)
(let* ((q (mailbox.queue mbox))
(tail (member-if test q)))
(setf (mailbox.queue mbox) (nconc (ldiff q tail) (cdr tail)))
(return (car tail)))))))
there would be no guarantee that the part inside WITH-LOCK isn't
interrupted, e.g. by PROCESS-INTERRUPT to run the SLIME debugger. But
the debugger, sooner or later, calls RECEIVE-IF in the same thread;
recursively so to say. It could happen that the debugger removes the
the element that the suspended call was about to remove, i.e. both
calls would, after the debugger resumes, return the same element.
Disabling interrupts inside the WITH-LOCK didn't seem right either,
because then the interrupt handler would be delayed, but still be run in
the dynamic extend of the lock and so blocking any sender.
That's pretty unfortunate mix of threading and interrupts. The current
variant with the timeout appeared to me as the least broken. But I
would love to learn how to do this properly.
More information about the slime-devel