-
-
Save minikomi/0bf7bedb64767a832be172c5b0767d1e 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
(let [v (atom [0 0 0 0 0]) | |
threads (for [i (range 5)] | |
(let [t (Thread. | |
(fn [] | |
(dotimes [_ 1000] (swap! v update i inc)) | |
))] | |
(.start t) | |
t))] | |
(doseq [t threads] (.join t)) | |
@v) | |
(let [v (volatile! [0 0 0 0 0]) | |
threads (for [i (range 5)] | |
(let [t (Thread. | |
(fn [] | |
(dotimes [_ 1000] (vswap! v update i inc)) | |
))] | |
(.start t) | |
t))] | |
(doseq [t threads] (.join t)) | |
@v) | |
(let [v (transient [0 0 0 0 0]) | |
threads (for [i (range 5)] | |
(let [t (Thread. | |
(fn [] | |
(dotimes [_ 1000] (assoc! v i (inc (get v i)))) | |
))] | |
(.start t) | |
t))] | |
(doseq [t threads] #(.join t)) | |
(persistent! v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment