Aktuelle Änderungen
Printable View
Änderungen
Bearbeiten
SoftwareArchitecture > PragmaticProgrammers > IntermediateLanguage > VersionControlSystem > VersionControl > JohannesSiedersleben > PythonSuccessStories > TailCallOptimization > Recursion > BehaviorDrivenDesign > SmartDataAndDumbCode > ProgrammingLanguages > ProgrammierSprachen > JavaEnterpriseEdition > DataDrivenProgramming > TestDrivenDevelopment > ClojureReferenceTypesClear Trail
Clojure

- coordinated: inside transaction
- http://groups.google.com/group/clojure/browse_thread/thread/539b967faaf84a65
- First, note that in talking about atoms/refs/agents we are talking about Clojure's reference types that allow changes to be seen by multiple threads, so these three reference types are all shared reference types.
- There are two dimensions to the choice about using them, the first is - will the changes be synchronous or asynchronous, and the second is, will a change to this reference ever need to be coordinated with a change to another reference or references.
- Atoms are synchronous, the change happens on the calling thread. They are as close to a plain variable as you get from Clojure, with a critical benefit - they are thread safe, in particular, they are not subject to read-modify-write race conditions. Your writes don't happen unless they are a function of what was read. But modifications to atoms are side effects, and thus need to be avoided in transactions.
- Agents are asynchronous, and that can have important benefits. In particular, it means actions get queued, and the sender can proceed immediately. They provide a transparent interface to the threading system and thread pools. Agents also cooperate with transactions in ways that atoms cannot - e.g. agent sends are allowed in transactions and get held until commit.
- What that means is that, if you build your state transformation functions as pure functions, you can freely choose/switch between the different reference types, even using the same logic for two different reference types.
- http://en.wikibooks.org/wiki/Clojure_Programming/By_Example
- Refs are 'coordinated' while agents and atoms are 'uncoordinated'. This means that in a multi-threaded environment, refs are modified in a transaction which ensures that only one thread can modify the value at a time. Whereas atoms and agents queue up change functions to ensure that the changes occur atomically. All of them are 'safe', they just use different strategies to provide this 'safety'.