[concurrency-interest] ForkJoinTask enhancement suggestion

Wolfgang Baltes wolfgang.baltes at laposte.net
Sun Mar 4 23:26:44 EST 2012


Hi,

Looking at the ForkJoin framework, I miss the ability to create a new 
'done' task with a given value. This is useful if - at a certain point 
of recursion - the result value of a task to be created is already 
known, but one wants to create the task anyway so that it integrates 
more easily with the existing algorithm, or to hand over the value to 
another process wrapped in the task.

I know one can already do this using the complete(v) method of 
ForkJoinTask, but this method requires a CAS instruction to change the 
tasks state, which I would like to avoid by setting the state/status 
before construction finishes. My proposal is to consider adding a new 
constructor ForkJoinTask(V) that a) sets the value, and b) sets the 
state to NORMAL. Although it may be consistent to also add a constructor 
to create an "exception task", I do not think this is necessary because 
of less frequent use, and hence less overall performance impact.

Noticing that tagging will also be available in a forthcoming version of 
the framework, it may make sense - for better performance and 
consistency - to also add the constructor ForkJoinTask(V, short) and the 
method complete(V, short), which allow setting both the value and the 
tag simultaneously.

Regards,
Wolfgang.


More information about the Concurrency-interest mailing list