Hi,

On Tuesday, September 30, 2014 12:01:33 PM UTC+2, Joachim De Beule wrote:
>
> Dear list,
>
> I've got two threads that update the same location. One of them takes a 
> lot of time. Given this, my question is if there is a reason to prefer an 
> atom or a ref? 
>
>
is it really just two threads?  Then the duration does not really matter 
and the slower will obviously commit later.  

I see no reason to use Refs in your example, because you do not change more 
than one in a transaction which is the main difference between Refs and 
Atoms.

Should you have lots of fast threads and one or a few slow threads, you may 
run into problems.  Refs try to adapt to the situation by storing a history 
of values which may lead to the slow transaction finally committing.  You 
can still get an exception from dosync when the transaction tried 10.000 
times to commit and failed (number from the top of my head; may be 
different).

FWIW, I have some code for demonstrating the issues at 
http://clojure-buch.de/listings/concurrency.txt (search for history stress 
test; comments in German because they are from my German clojure book).


Best,
stefan


-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to