This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-07
Channels
- # aleph (1)
- # beginners (152)
- # cider (26)
- # clara (2)
- # cljs-dev (13)
- # cljsrn (5)
- # clojure (198)
- # clojure-greece (15)
- # clojure-italy (39)
- # clojure-sanfrancisco (3)
- # clojure-spec (28)
- # clojure-uk (16)
- # clojurescript (52)
- # community-development (15)
- # core-async (26)
- # cursive (42)
- # data-science (28)
- # datomic (19)
- # devops (7)
- # duct (11)
- # emacs (24)
- # fulcro (22)
- # garden (4)
- # leiningen (12)
- # luminus (1)
- # mount (5)
- # off-topic (106)
- # om (5)
- # onyx (10)
- # parinfer (37)
- # re-frame (17)
- # reagent (47)
- # shadow-cljs (36)
- # yada (2)
How do go
blocks "unpark" themselves? IIUC , when they part they release the thread to work on another go
block. What tells the thread that the first go
block is ready to be worked on again?
@xiongtx go blocks don't park as much as they turn themselves into a callback (could be though of as a continuation). So when they "park" they simply attach a callback to something. Most of the time it's handed to a call ot (async/put! c v callback)
@tbaldridge Found this extremely helpful walkthrough of core.async/go
:
http://hueypetersen.com/posts/2013/08/02/the-state-machines-of-core-async/
IIUC the channel is responsible for restarting the state machine.
there’s an async-dispatch process that matches up channel reads and writes to resumption of pending reads and writes in eligible go blocks (expressed as callbacks)
the channel itself is a queue used by that disptach process as I understand it
(though now that I think of it more there must be a mechanism that marks the channel for potentially activating go blocks when the channel is read or written outside of a go state machine)
oh, I thought I’d seen this in my stack traces
the acting of publishing or consuming from a channel can cause things to be run on a threadpool
oh, so it is the channel driving it, like @xiongtx was saying? cool
right, now I see that thread-pool-executor names its threads async-dispatcher-%d
for N threads
I misinterpreted those in my stack traces
Can you elaborate on this a bit more? I’ve some basic understanding of how Java GC works, but what makes something a root?
ahh, they can get gc’d if the relevant channels are gc’d? - it’s starting to make more sense now I think
@noisesmith The point is that it’s cooperative multithreading; there’s no scheduler involved. This also means that the runtime cannot help you when you perform IO in a go
block.
Eli Bendersky has a great piece on this: https://eli.thegreenplace.net/2017/clojure-concurrency-and-blocking-with-coreasync/
@xiongtx I wasn’t imagining a preemptive scheduler, I was imagining a book-keeper that figured out which parked things were able to run
but of course the channels are fully qualified to do that, so there’s no need for such a book-keeper
regarding gc roots, a gc root is data that the gc can’t claim implicitly - for example if you have cyclical object references that contains no path to a root, all objects in that cycle qualify for gc
but if they are accessible from a root they remain alive
I understand that part…I guess the point is that since there’s no “book-keeper” for the go
blocks they’re not reachable from any GC root?
B/c nothing holds a (strong) reference to them unless it’s 1) the thread that’s running the block or 2) the channel that uses the SM as a callback
I think that not only are those the only strong references, but those are the only references period unless you do some shenanigans