Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created November 25, 2009 01:21
Show Gist options
  • Save tmountain/242388 to your computer and use it in GitHub Desktop.
Save tmountain/242388 to your computer and use it in GitHub Desktop.
(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