Skip to content

Instantly share code, notes, and snippets.

@noidi
Created August 29, 2012 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noidi/304b72eb346cdc42898f to your computer and use it in GitHub Desktop.
Save noidi/304b72eb346cdc42898f to your computer and use it in GitHub Desktop.
(defn concurrency-test2 []
(let [test-atom (atom 0)]
(letfn [(make-agent []
(agent 10))
(run-agent [n]
(if (zero? n)
n
(do
(send *agent* run-agent)
(swap! test-atom inc)
(dec n))))]
(reset! test-atom 0)
(let [agents (repeatedly 50 make-agent)]
(doseq [a agents]
(send a run-agent))
(apply await agents))
(println @test-atom)
(Thread/sleep 100)
(println @test-atom))))
(concurrency-test2)
; 199
; 500
;= nil
(concurrency-test2)
; 453
; 500
;= nil
(concurrency-test2)
; 181
; 500
;= nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment