--
R. Mark Volkmann
Object Computing, Inc.
I just ran across this quote from Rich Hickey near the bottom of
http://mail.google.com/mail/?ui=2&zx=gb3mbfrah3gv&shva=1#inbox/12014881fc65b5c1
“Clojure's STM and agent mechanisms are deadlock-free. They are not
message-passing systems
with blocking selective receive. The STM uses
locks internally, but does lock-conflict detection and resolution
automatically.”
I take this to mean that it is not possible for STM transactions in
Clojure to deadlock. I'm still interested in learning the basics of
how it does lock-conflict detection and resolution. I haven't found a
description of it anywhere. I guess I'll have to read through the
code.
You certainly don't owe anyone a written summary of how any parts of
Clojure work. However, surely you would agree that if such summaries
existed, it would be easier for people interested in Clojure to get a
general understanding much faster than reading the code. As an
example, when people want to know how threads and locks work in Java,
they don't usually look at the source code. There are plenty of
tutorials on the web and books that explain it.
In my case I'm having a semi-debate with someone about why coding for
concurrency is easier in Clojure than in Java. The person I'm
discussing this with thinks that Clojure is oversimplifying
concurrency issues. He feels it is necessary to have a detailed
understanding of an entire application in order to avoid deadlocks. I
was looking for something that might convince him that it isn't true
and that deadlocks cannot occur in Clojure. I don't think you can
expect someone like him that is barely interested in Clojure to look
through the source. On the other hand, if there was a page on the
Clojure website that explained at a high level how Clojure avoids
deadlocks, I think he would read that.
I do understand though how not documenting certain things leaves you
free to change the implementation later.
Thanks Rich! I've actually finished reading the Wikipedia entry for
STM this morning and it helped me a lot. I haven't looked at the other
two yet though, so I'll do that.
> The bottom line is that STM implementations are complex and won't have
> simple descriptions.
>
> If the person you are arguing with can't understand how concurrency
> could be made automatic and deadlock free, have him imagine an STM
> where each ref had a unique locking number and a revision, no locks
> were taken until commit, and then the locks were taken in locking
> number order, revisions compared to those used by the transaction,
> abort if changed since used, else increment revisions and commit.
> Deadlock-free and automatic. It ends up that no STM works exactly this
> way, but it is an example of how the deadlock-free correctness benefit
> could be delivered simply.
Thanks! That helps.
|
Luc Préfontaine Armageddon was yesterday, today we have a real problem... |