This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-14
Channels
- # adventofcode (14)
- # announcements (3)
- # babashka (18)
- # beginners (32)
- # calva (1)
- # clj-kondo (65)
- # cljs-dev (5)
- # cljsrn (3)
- # clojure (22)
- # clojure-spec (13)
- # clojure-uk (53)
- # clojured (3)
- # clojuredesign-podcast (50)
- # clojurescript (8)
- # core-async (32)
- # cursive (15)
- # data-science (1)
- # datomic (17)
- # fulcro (48)
- # hyperfiddle (1)
- # off-topic (5)
- # shadow-cljs (2)
- # testing (2)
But when "blocked" on a channel it yields the thread. But the amount of data the go block hangs on to can easily dwarf the amount of data needed for thread bookkeeping. So what even is lightweight?
So, a go block is just description of work, and a thread might pick it up and do a bit of it till time slice runs out or it hits a blocking call. Is that correct?
(the native thread it is running on of course can be preempted, but the go block has no idea of that happens and it doesn't cause it to yield the thread to other go blocks)
Blocking io, taking locks, burning cpu without doing channel ops will all blockup the thread pool where go blocks run
The go macro is also a statically scoped transformation. So it only rewrites it's immediate body.
You are referring to the concept where a go block stops at the function boundary? I read the official guide but did not understand it fully.
it will not work if you move <!
into a function, it has to be in the go block
I was a bit confused by that too. As a beginner, reading some of the documentation can be hard to unpick
The parking functions only work in a go macro because the go macro rewrites the code around it. So once you call into a function the go macro can no longer “see” it to do any rewriting
So, if I have something like this (go (if (pos? x) (anotherns/my-function x)))
, then what execution context will my-function
have? In the sense of threads? On the same thread as the go-block, or elsewhere?
The same as the go block, and if my-function does any blocking operations it will clog up the threadpool
understood about blocking, I'm trying to understand better, It's just that I'm trying to consoldate this "once you call into a function, the go macro...", with what happens when I call into a function, and how threads etc. are maintained/created
function boundary means if there's a fn
form between go
and a parking form, it's not considered to be part of it
so e.g in the following form (go (fn [] (<! c)))
the <!
will not be rewritten, and thus is illegal