On Feb 20, 6:07 am, Jack Fang <jack.fang1...@gmail.com> wrote:
>    Suppose the transfer-money and print-info are run in different
> thread. With the current Clojure STM, is it possible that print-info
> prints the old source-account information and modified dest-account
> information?  

Yes.

> Do I need to add a dosync to the print-info function? I
> read the Programming Clojure. It says do not have side-effect on a
> transaction.

If you want consistent results between refs, you'll need to be in a
transaction, thus dosync.  You might also need to use ensure, but I'm
not certain.  The reason side-effects are discouraged (not forbidden)
is because a transaction may be run multiple times, thus you might get
multiple printouts.

> If I add dosync to the print-info, do I need to use agent

Agents are desgned to be used for side-effects in a transaction.
That's why sends to an agent are held and only actually happen if the
tx commits.  It mIght be overkill for your examle, but yes send
ensured/altered values to an agent from inside a dosync block.
> to print the info?

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