Re: Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-05 Thread Steven E. Harris
Stuart Halloway stuart.hallo...@gmail.com writes: It is mort important to focus on the semantics (commutative or last- one-wins) than the implementation details. That's a tough pill to swallow. I understand the benefits of specifying behavior to allow flexibility in an implementation, but here

Re: Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-02 Thread Steven E. Harris
Meikel Brandmeyer m...@kotka.de writes: So using alter is the absolutely correct and nothing bad will happen. However you might construct superfluous default nodes in case the action is retried. They are not assoc'd to the map, though. Understood. Thanks for the explanation. The anonymous

Re: Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-02 Thread Stuart Halloway
If so, there's more to be explained about `commute'. I'm imagining the commit-time rules saying that if competing changes to the refs touched by `commute' can be ignored, because the changes can be applied in either order. But if the operation was something like `inc', two competing threads would

Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-01 Thread Steven E. Harris
My application involves a graph with a node set, represented as map from integral node ID to a node structure. Several threads need to look up these node structures. This graph is constructed lazily, by which I mean that the structures representing the nodes are only instantiated upon first

Re: Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-01 Thread Meikel Brandmeyer
Hi, disclaimer: I'm completely incompetent in terms of the STM. The following is my understanding what happens. It might be completely wrong. Ignore at will. On Mar 2, 2:40 am, Steven E. Harris s...@panix.com wrote:   (dosync     (or (*id-node-map* id)         (alter *id-node-map*