Hi,

I just want to address this issue (CLJ-1498 
<http://dev.clojure.org/jira/browse/CLJ-1498>). It was accepted in 
1.7-alpha2 and I haven't seen a lot of discussion around it, even though 
it's quite a big change.

With this change the following code is possible:

(let [m (transient {:a 0})
      futs (for [n (range 100)]
             (future (assoc! m :a (inc (:a m)))))]
  (mapv deref futs) ; wait until futures are done
  (persistent! m))


The results will vary per run, where it used to throw 
an IllegalAccessError: "Transient used by non-owner thread".

I understand the problems of not being able to have 1 go routine access a 
transient, even though it would be safe, but this solution feels like it's 
throwing out the baby with the bathwater. Basically, it's doing away with 
what the following block on clojure.org <http://clojure.org/transients>
 says:

*Transients enforce thread isolation**.* Because each result of a transient 
> operation shares (mutable) structure with the previous, it would be very 
> dangerous if more than one thread were to manipulate a transient at once. 
> In order to prevent this, transients will detect any (read or write) use 
> from a thread other than the one that created them and throw an exception.

 

>
> This may not sound like a concurrency story, but single-thread isolation 
> is actually a very useful concurrency semantic. The whole point of using 
> transients is that doing so is safe, because their use is an isolated 
> implementation detail of otherwise functional code. Having that be enforced 
> means that some things that would normally be very hard to make safe with 
> ordinary mutable data structures become easy.


I don't have a good solution for dealing with transients and logical 
threads, but I would much prefer keeping the semantics of transients as 
they are and maybe pass an option to transient to disable owner checking.

-- 
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/d/optout.

Reply via email to