> (def a (atom {})) 
>
> (defn add-kv [k v] 
>    (swap! assoc k v)) 
>
> If I call add-kv from multiple threads, how can I assume that the map 
> won't be modified in the middle of the assoc? Sure, I could lock, but 
> read this article first: 
> http://en.wikipedia.org/wiki/Non-blocking_algorithm 
>
> The idea is that with atoms there will always be some progress. Even 
> if one updater takes an hour to complete, the other threads can 
> continue as needed. True that single thread will not complete until 
> there is a 1 hour window, but that's where other synchronization 
> methods come into play (worker queues, for example). 
>
> Timothy 
>

The "making progress" seems an illusion here to me. Sure, you can make 
progress in one thread while another thread is taking one hour to finish 
its part. But the cost is the "long" thread finally found out "oops, I have 
to start over my one-hour job". 

Being lockless seems useful for certain cases (like real-time system as 
mentioned in the Wikipedia article). But I still could not grasp the idea 
how it can increase *real* work throughput, as the problem itself mandates 
a part of the work can only be done in serial.




-- 
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