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 I think the
behavior is still underspecified. Or maybe it's just hasn't been
described well with enough comparative examples to allow it to sink
in. It feels like some of our discussion is still operating on
superstition.

> If you care about ordering, stick to alter. If you aren't sure, stick
> to alter.

Got it.

> I find a counter to be a useful example. If the purpose of the counter
> is to keep a total count of something that happened, then you can use
> commute.

This is true because even if commute runs once and increments the
counter, but then runs into a conflict, the commute operation will be
run again on a fresher value until it finally succeeds in committing
without conflict. This is similar to a manually-written atomic increment
operation using CAS in a spinning loop:

  for (int cur = val.get();
       !val.compareAndSet(cur, cur + 1);
       cur = val.get())
    ;

Or:

  int cur;
  do
  {
    cur = val.get()
  }
  while (!val.compareAndSet(cur, cur + 1));

> But if the counter is used as an id generator within the transaction,
> then order matters and you have to use alter.

The key there is "within the transaction", because if you used commute,
the commuted operation could be repeated upon conflict at the end of the
transaction and wind up succeeding, albeit with a different resulting
value than the one observed within the transaction, right?

-- 
Steven E. Harris

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to