The Clojure STM uses multiversion concurrency control with adaptive history queues for snapshot isolation, and provides a distinct commute operation
I have been reading myself up on Clojure concurrency, starting at [1]. In [2] I read thatThe Clojure STM uses multiversion concurrency control with adaptive history queues for snapshot isolation, and provides a distinct commute operationbut it still needs some explanation to me. Software transactional memory (STM) is described ok.But the "adaptive history queues" looks like implementation. In ADA, tasks on rendezvous queue up (so the Ravenscar high security profile prohibits them because they are non-deterministic). In Go goroutines on selective choice's select are queued (also nondeterministic). In occam the there is no such queue on the ALT. How is the Clojure queue, and what does it contain?I see that exchanging data between Clojure concurrent functions (threads?) described. But I haven't discovered how a "thread" that succeeds in writing, followed by a successful write immediately after by another thread - is "signalled" to the first thread? Is there any wait type of mechanism?
If a write fails and there is a retry, what's the limit of retries, is there a yield in between, and in case, how is this entry queued?
Is it correct to say that never to block means never to be 100% sure that a transaction succeeds at first attempt?
[3] states on commute that "Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. commute allows for more concurrency than ref-set.". What's the metric of concurrency? No, little, some, more, much, max?
On Sunday, October 26, 2014 11:37:43 AM UTC+1, Øyvind Teig wrote:I have been reading myself up on Clojure concurrency, starting at [1]. In [2] I read thatThe Clojure STM uses multiversion concurrency control with adaptive history queues for snapshot isolation, and provides a distinct commute operationbut it still needs some explanation to me. Software transactional memory (STM) is described ok.But the "adaptive history queues" looks like implementation. In ADA, tasks on rendezvous queue up (so the Ravenscar high security profile prohibits them because they are non-deterministic). In Go goroutines on selective choice's select are queued (also nondeterministic). In occam the there is no such queue on the ALT. How is the Clojure queue, and what does it contain?I see that exchanging data between Clojure concurrent functions (threads?) described. But I haven't discovered how a "thread" that succeeds in writing, followed by a successful write immediately after by another thread - is "signalled" to the first thread? Is there any wait type of mechanism?There is no signalling. The "write" in the first thread always succeeds within the transaction but the "real world" is not affected until the transaction succeeds as a whole. If during the transaction another transaction succeeded, it is retried as a whole, potentially with the new values written by the other transaction, until it has also succeeded.
If a write fails and there is a retry, what's the limit of retries, is there a yield in between, and in case, how is this entry queued?There is no limit. (Unfortunately I don't know about the implementation details and hopefully somebody else can enlighten you on that.)Is it correct to say that never to block means never to be 100% sure that a transaction succeeds at first attempt?Yes.
[3] states on commute that "Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. commute allows for more concurrency than ref-set.". What's the metric of concurrency? No, little, some, more, much, max?How much happens at the same time in contrast to being queued up. Remember that only successful transactions affect the outside world. E. g.: Of two successful transactions, one had to be restarted because of the other completed during its first try => The two successful transactions didn't happen in parallel. Using commute reduces the potential of a retry and thus allow more successful transactions in parallel => more concurrency.
Transactions themselves are not queued (besides the obvious queueing
of threads when you have more threads than cores). What gets
adaptively queued is the historical values of refs involved in
transactions.
So if you have three concurrent transactions running, and three refs
are involved in two of these transactions, and a fourth refs in
involved in all three, the system will probably need to keep two
previous values for the first three refs and three previous values for
the last ref.