Uploaded image for project: 'Clojure'
  1. CLJ-1498

Remove birth-thread check from transients

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.6
    • Fix versions: Release 1.7
    • Approval:
      Ok
    • Patch:
      Code

      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:

      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:

      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.

        Attachments

          Activity

            People

            • Assignee:
              alexmiller Alex Miller
              Reporter:
              richhickey Rich Hickey
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: