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

Create volatile box for managing state

    Details

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

      Description

      Motivation:

      Clojure needs a faster variant of Atom for managing state inside transducers. That is, Atoms do the job, but they provide a little too much capability for the purposes of transducers. Specifically the compare and swap semantics of Atoms add too much overhead. Therefore, it was determined that a simple volatile ref type would work to ensure basic propagation of its value to other threads and reads of the latest write from any other thread. While updates are subject to race conditions, access is controlled by JVM guarantees.

      Solution overview: Create a concrete type in Java, akin to clojure.lang.Box, but volatile inside supports IDeref, but not watches etc.

      API:

      (volatile! x) ;;ctor
      (vreset! vol newval) ;;like reset
      (vswap! vol f args) ;;same shape as swap!, but MACRO over vreset!
      

      Patch: volatile3.diff

      Screened by: fogus

        Attachments

          Activity

            People

            • Assignee:
              richhickey Rich Hickey
              Reporter:
              richhickey Rich Hickey
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: