On Mon, Jun 24, 2013 at 4:17 PM, Cedric Greevey <cgree...@gmail.com> wrote:
> Ah, thanks. The locking granularity is local to the cons cell (or > analogue; first/rest pair) being realized, I hope? So one thread actually > calculates an element and neither call returns until it's calculated, and > then both promptly return the calculated value, but threads realizing other > lazy seqs or crawling along earlier parts of the same one don't get blocked? This is correct, as far as I understand it. One will do the work, the other will block (awaiting a lock). The first will return, relinquishing the lock and allow the other to get the computed value too. The granularity could be anything from a single cons cell to the entire seq. In the following instance the evaluation of the thunk will yield the entire vector in one operation, which is synchronized. (The `println` is there to make clear when/how evaluation takes place.) (def lazily-initialized-vector (lazy-seq (mapv println (range 10))) What gets returned by the thunk is entirely dependent on the thunk. LazySeq just relies on being able to call `seq` on it. Presumably for fully lazy sequences it will generate one element at a time, and for chunked sequences it will generate one chunk at a time. (Just for the record, I don't have any particular knowledge of the Clojure internals, but I'm fairly confident in my speculation.) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.