This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-29
Channels
- # beginners (10)
- # cider (10)
- # cljs-dev (17)
- # clojure (14)
- # clojure-losangeles (1)
- # clojure-spec (1)
- # clojure-uk (3)
- # clojurescript (49)
- # core-async (5)
- # css (1)
- # datomic (2)
- # duct (26)
- # emacs (13)
- # figwheel (6)
- # figwheel-main (5)
- # garden (1)
- # keechma (6)
- # nrepl (1)
- # off-topic (6)
- # re-frame (52)
- # shadow-cljs (132)
- # spacemacs (4)
- # tools-deps (26)
So I was trying to observe contention over swap!
ing an atom via 1000 futures/threads, and naturally when using println
you get hilarious and useless results. I then thought to make a huge core.async channel (e.g. with a 10000 long buffer) to serialize printing, thinking that there would be no locks to muck up my observations, but it seems there is some fishy behaviour going on there.
(def print-chan (a/chan 100000))
(defn aprintln [& args]
(a/put! print-chan args))
(aprintln "hello " "from" " chan")
(a/go-loop []
(apply println (a/<! print-chan))
(recur))
This is working as expected, but combined with:
(defn up! [x]
(let [t (Thread/currentThread)]
(aprintln "attempting to increment:" x " from " t " id " (.getId t))
(inc x)))
(doseq [x (range 1000)]
(future (swap! thingy up!)))
I see thingy
which is an atom, only go up to ~800, whereas of course it should be 1000.