[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: advice needed for multi-threading patch

From: Stefan Monnier
Subject: Re: advice needed for multi-threading patch
Date: Sun, 27 Sep 2009 19:05:07 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Stefan> Indeed.  The lock should probably be on the buffer-local binding itself
Stefan> (i.e. the combination of the buffer and the variable).

> I looked into this a bit; I think it can lead to deadlock too easily:
>  Thread A acquires V1 and requests V2
>  Thread B acquires V2 and requests V1

> Instead, I think we could remove the buffer lock.  Because we currently
> use cooperative threading, most buffer operations are atomic with
> respect to thread switches.  So, it seems that if we fix the bindings
> problem, we can probably just remove the buffer lock.

Removing locks sounds like a wonderful solution, but it's dangerous.
I think you understand the danger and refer to it as "the bindings
problem".  But since I'm not sure I'll state what I think is the

thread T1 goes into buffer B and does a dynamic let-binding of
buffer-local variable X with value V1, then thread T2 does the same
thing with value V2.
What should that mean?

What should T1 see when it looks at X, V1 or V2?
What should T2 see when it looks at X, V1 or V2?
What did T2 see when it looked at X before let-binding it, V1 or V0?
What should T1 see when it looks at X after T2 ends its let-binding, V1 or V0?
What should T2 see when it looks at X after T1 ends its let-binding, V2 or V0?

You have to consider those cases and then look at existing code and see
what that code would expect.  A good variable to start with is probably
default-directory (one of the most common buffer-local-and-let-bound
variables I know of), but others need to be considered as well (I'm not
sure they'll all agree on the behavior they expect).


PS: Of course, similar questions arise with let-binding frame-local and
terminal-local variables, but I think these are much less common, so
it's probably OK to be less careful with them and just fix up the places
that break using explicit locks or things like that.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]