We're updating the issue view to help you get more done. 

Remove birth-thread check from transients

Description

Transients protect themselves from use by any thread other than the one that creates them. This is good for safety, however it eliminates certain valid usages of transients. For example, usage in a go-block might occur in subsequent invocations across multiple OS threads (but only one logical thread of control).

Current simple test:

1 2 3 4 user> (def v (transient [])) #'user/v user> (persistent! @(future (conj! v 1))) IllegalAccessError Transient used by non-owner thread clojure.lang.PersistentVector$TransientVector.ensureEditable (PersistentVector.java:464)

Proposal: Remove the owner check from transient collections. (Leave the edit after persistent check as is.) The test above should succeed.

After:

1 2 3 4 user=> (def v (transient [])) #'user/v user=> (persistent! @(future (conj! v 1))) [1]

The clj-1498-3.diff version of the patch also replaces the AtomicReference<Thread> with AtomicBoolean as we can now track just ownership, not who owns it.

Doc update: Various pieces of documentation will need to be updated with this change, namely http://clojure.org/transients

Patch: clj-1498-3.diff

Alternative: Another idea would be to make this check optional with some kind of option on the transient call (transient coll :check-owner true). Not sure whether what the default would be for that.

Environment

None

Status

Assignee

Alex Miller

Reporter

Rich Hickey

Approval

Ok

Patch

Code

Fix versions

Affects versions

Release 1.6

Priority

Major