Just checking my understanding.

It seems to me that it is not possible for Clojure to remove the
possibility of writing code that has race conditions. I could write
code in which two threads each change the value of the same Ref inside
a transaction. Let's say the Ref starts with a value of 2, one
transaction adds 3 and the other multiplies by 4.
Depending on which thread runs first, after they both complete the
value of the Ref will either be (2 + 3) * 4 = 20 or (2 * 4) + 3 = 11.
Of course as the developer I could decide to use an Agent instead of a
Ref and then send actions to the Agent in the order in which I want
them to run to fix this problem. But Clojure itself can't prevent this
situation. The developer has to recognize the potential race condition
and write the code in a way to avoid it. Sound correct?

Does Clojure STM eliminate the possibility of deadlock? When two
transactions have a contention for the same Ref, Clojure gives
preference to the transaction that has been running the longest
(unless it has only been running for a very short amount of time - see
bargeTimeElapsed in LockingTransaction.java). Is that alone enough to
guarantee that a deadlock over Refs cannot occur? The transaction that
has been running the longest may never finish, going into an infinite
loop. Other transactions that contend for the same Refs will continue
retrying until they hit the 10,000 retry limit and then an exception
will be thrown, so I supposed technically that isn't deadlock.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to