Created
November 25, 2009 01:21
-
-
Save tmountain/242388 to your computer and use it in GitHub Desktop.
This file contains 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
(def num-threads 50) | |
(def data (ref 0)) | |
(defn hello [data] | |
(doseq [_ (range 500)] | |
(Thread/sleep (rand-int 1000)) | |
(dosync (ref-set data (inc @data))) | |
(println @data))) | |
(def threads (for [_ (range num-threads)] (new Thread #(hello data)))) | |
(doseq [t threads] (. t start)) | |
(doseq [_ (range 500)] | |
(Thread/sleep (rand-int 1000)) | |
(println "main thread")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment