hg: lambda/lambda/jdk: Summary: add ThreadLocal(Factory<T>) and compareAndSet methods

Doug Lea dl at cs.oswego.edu
Mon Jul 30 05:27:42 PDT 2012


On 07/30/12 07:16, Aleksey Shipilev wrote:
> I think these method names are bad:
>    int compareAndSet(IntUnaryOperator op);
>
> I think then names should be coherent with other high-level methods,
> like incrementAndGet, etc., i.e.:
>    int updateAndGet(IntUnaryOperator updater);
>    int getAndUpdate(IntUnaryOperator updater);
>


Thanks Aleksey. These are clearly better names. I hadn't
been paying much attention to this part of lambdafication
efforts. And I am still slightly ambivalent about them:
99% or so of updates in practice are adds (or increment, decrement).
The existing getAndAdd etc methods are planned to be specially
optimized into native atomic-add instructions on platforms
supporting them for JDK8 (especially post-pentium4 x86).
Since there are no plans for determining whether lambdaized
forms are adds (which would be heuristic at best), they would
be at a performance disadvantage. Which I suppose is OK for
the sake of added expressivity, but perhaps some disclaimers
could be added about this.

-Doug




More information about the lambda-dev mailing list