You do not have to. Everything inside your dosync-block will happen
atomically, meaning print-info will either see the values of source-account
and dest-account before your transaction happened or after it's done his
work.

--
Ph. Siegmantel

2010/2/20 Jack Fang <jack.fang1...@gmail.com>

> Hi,all
>
>      I am new to clojure.  Now I hava a problem about read
> transcation.
>      Suppose now I write some code about bank transfer. So this is
> the source-account and destination-account
>
> //The code
> (def source-account (ref 1000))
> (def dest-account (ref 0))
>
>    And I have a function to do the account transfer.
> //The code
> (defn take-money [account num]
>  (- account num))
>
> (defn despoite [account num]
>  (+ account num))
>
> (defn transfer-money [num]
>  (dosync (alter source-account take-money num)
>          (alter dest-account despoite num)))
>
>    And I have a another function to print the source account and dest
> acoount information.
> //The code
> (defn print-info []
>  (do
>    (println @source-account)
>    (println @dest-account)))
>
>   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?  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 I add dosync to the print-info, do I need to use agent
> to print the info?  Hope somebody can help me.
>
> Thank.
> Jack
>
>
> --
> 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<clojure%2bunsubscr...@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 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