On Fri, Dec 26, 2008 at 8:35 PM, Adrian Cuthbertson
<adrian.cuthbert...@gmail.com> wrote:
> It's important to distinguish between updating atoms within
> transactions and outside transactions. In the former case, one has to
> ensure the update function can be retried without ill-effects.
> However, outside a transaction, atoms are just mutable values, that
> can safely be shared between threads, provided that their updating
> does not need to be coordinated with other updates (to other atoms,
> refs or agents).

Yes, but when you write your atom-based code, you have no way to know
whether you or others who want to reuse it will want to use it as part
of a transaction.  atom-based code is not generally safe for
transactions, which is why I suggested it should be avoided.  In your
example, if incserid is used in a transaction, it is possible that
certain serids will be skipped.  This may be acceptable, in which
case, go ahead and use an atom, but often programs rely on subtle
assumptions (like the serids will be issued consecutively), and your
program can become brittle if there's a chance your code won't follow
these assumptions.  Probably better off not to take the chance.  Stick
with something like refs which will yield more predictable behavior,
and thus be easier to test.  Memoization is a very special exception,
because it really doesn't matter if something gets cached more than
once.

The whole point of Clojure seems to make as much code as possible safe
for its software transactional memory.  Thus the persistent data
structures, and other design details.  Although interoperating with
Java also produces risk within transaction, generally speaking, if you
stay within the "Clojure core", you're safe for transactions.  Except
atoms.

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