[slime-devel] Re: Use of with-lock inside without-interrupts
Nikodemus Siivola
nikodemus at random-state.net
Wed Aug 6 11:35:29 UTC 2008
On Tue, Aug 5, 2008 at 11:51 PM, Helmut Eller <heller at common-lisp.net> wrote:
> * 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?
We talked briefly about a related issue in ECLM this year. :)
> 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.
In SBCL The Right Thing would be:
(let (got-it)
(without-interrupts
(unwind-protect
(when (setf got-it (allow-with-interrupts (get-mutex lock)))
...frob-queue...)
(when got-it
(release-lock lock)))))
and GET-LOCK has the wait wrapped in WITH-INTERRUPTS.
WITH-INTERRUPTS enabled interrupts only if there is an active
ALLOW-WITH-INTERRUPTS lexically nested inside each WITHOUT-INTERRUPTS
currently on stack. (This is what I was trying to explain while
slightly too drunk to make a great deal of sense.)
So: frobbing the queueu is protected from interrupts, and unwinds are
protected as well, as is the actual action of grabbing the lock -- but
waits can be interrupt.
There is are a couple of internal variants as well, which don't enable
interrupts at all, etc -- which are used only when the wait is (we
hope!) known to be finite, and the wrapped code is also known to
finish very shortly. (Or when interrupts are a really bad idea
anyways.)
Cheers,
-- Nikodemus
More information about the slime-devel
mailing list