[concurrency-interest] ForkJoin updates

Alex Lam S.L. alexlamsl at gmail.com
Sun Mar 4 18:13:20 EST 2012


On Sun, Mar 4, 2012 at 10:35 PM, Doug Lea <dl at cs.oswego.edu> wrote:
>
>> The methods are a little annoying to use though because there are no
>> "short"
>> literals, so you have to say for example: if
>> (task.compareAndSetForkJoinTaskTag((short)0, (short)1)) ... to
>> conditionally
>> add a simple mark. ...
>
>
>> As for the API - in OutputStream for example, they provide the write()
>> method
>> using "int", but document them such that only the lowest byte is used:
>>
>
> In the bondage-and-discipline spirit of most of j.u.c :-),
> I'd rather force the users of this API to explicitly acknowledge that
> they are using a narrower-than-usual type. This seems OK mainly because
> these tags are uninterpreted, and are made available so that thin layers
> on top of FJT can be more time/space efficient than they could otherwise
> be in the vastly most common case where there is only a small range of
> possible tags. For example, those that internally translate enums that
> are known to have only a few values:
>
> enum Relationship { LIKES, FRIENDS, INVITES }
> abstract class SocialNetworkGraphTask extends ForkJoinTask<Void> {
>  void visit(Relationship r) {
>     short tag = (short) (1 << r.ordinal());
>     ...
>     if (compareAndSetForkJoinTaskTag(..., tag))
>         process();
>  }
>  ...
> }
>
> More compelling use cases include various forms of completion-task
> designs. I'll post more about these hopefully soon.

Looking forward to seeing them.

I have a computation-intensive app dealing with 2D geometry which I
have been evaluating various design for ForkJoin on JavaSE 7, so would
welcome any new ideas.

(Slightly OT - one of these days I will try to fix those rounding bugs
in java.awt.geom.Area for good!)


> On the other hand, there is no reason to make common sensible
> CAS-based idioms on tags any more tedious than necessary. So it seems
> reasonable to at least provide a more streamlined way to add a value:
>  short getAndAddToForkJoinTaskTag(short delta)
>

About those really long method names - is the original reason for
"mark" still applies to "tag"? Can we just come up with an obscure
term instead of "tag" so we can do away with the "ForkJoinTask" bit?

Doesn't hurt my fingers that much since I use an IDE, but my eyes...!


Alex.



More information about the Concurrency-interest mailing list