Created
September 2, 2010 17:58
-
-
Save na-ka-na/562631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(dotimes [_ 10] | |
(let [a (ref -100) | |
f1 (future (dosync (println "Trying T1") | |
(if (= @a 10) | |
(ref-set a @a) | |
(do (Thread/sleep 4000) | |
(println "Done T1"))))) | |
_ (Thread/sleep 1000) | |
f2 (future (dosync (println "Trying T2") | |
(ref-set a 15)))] | |
(deref f1) | |
(deref f2) | |
(println @a) | |
(println "------------") | |
(Thread/sleep 1000))) | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Trying T1 | |
Trying T2 | |
Done T1 | |
15 | |
------------ | |
Please comment if anyone gets: | |
Trying T1 | |
Trying T2 | |
Trying T1 | |
Done T1 | |
10 | |
-------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment