On Thu, Jan 22, 2009 at 2:18 PM, Rich Hickey <richhic...@gmail.com> wrote:
>
> Those are important things to think about.
>
> There are, in fact, thread semantics for the streams mechanism, as for
> the rest of Clojure. Currently, I've made it such that the stream/iter/
> seq combination ensures serialized access to the generator, allowing
> use of generators over otherwise unsynchronized multi-step activities.
>
> Obviously, stream-backed seqs are safe, being persistent and
> immutable. but it is also currently the case that the stream iter is
> MT safe as well. All calls to next! on an iter are atomic re: its
> generator, i.e. no 2 threads can be in the generator code at once.
> That means that, within a private consumer, you could fire up multiple
> threads that share the same iter and coordinate to produce a result,
> and return the result or a stream upon it.
>
> Used correctly, this is a powerful feature. However, I'm reluctant to
> expose/guarantee it, lest people start using iters as connection
> points and invalidating the whole stream protection model. A well-
> written API should take/return streams/seqs, never iters, so MT use of
> an iter should always be an implementation detail of a single stream
> step. But I can't enforce that.

Hmm... could we imagine a (synced-iter an-iter) that returned a
wrapped iter that _did_ guarantee MT safety?

Ofcourse this only makes sense if you end up not guaranteing MT safety
of ordinary iters, and I don't know enough to prefer one approach over
the other.

>
> For those looking to experiment with such things, feel free to try it
> now and provide feedback.
>
> Thanks,
>
> Rich
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to