Hi Chouser,
On Mon, Mar 15, 2010 at 11:27 PM, Chouser <[email protected]> wrote:
> I make no claims about the Rightness of this suggestion, but
> simply offer another example of a work-around:
>
> (dosync (alter r identity) (alter r f))
>
> That is, a "dummy write" via alter is also sufficient to allow
> the transaction to succeed, just like 'ensure'.
>
This is an interesting idea which can be automated (well, to be frank, an
implicit ensure could also be automated but it doesn't feel kosher) by
adding a doAlter to c.l.LockingTransaction:
Object doAlter(Ref ref, IFn fn, ISeq args)){
if(!info.running())
throw retryex;
if(commutes.containsKey(ref))
throw new IllegalStateException("Can't alter after commute");
Object val;
if(!sets.contains(ref))
{
sets.add(ref);
val = lock(ref);
}
else
val = vals.get(ref);
Object ret = fn.applyTo(RT.cons(val, args))
vals.put(ref, ret);
return ret;
}
and in c.l.Ref:
public Object alter(IFn fn, ISeq args) throws Exception{
LockingTransaction t = LockingTransaction.getEx();
return t.doalter(this, fn, args)));
}
What do you think?
Christophe
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en