[concurrency-interest] int[] in the ForkJoin example

Ashwin Jayaprakash ashwin.jayaprakash at gmail.com
Fri Aug 5 19:43:17 EDT 2011

The Fork-Join example/doc shows an int[] being written to by multiple
threads (
Each task writes to a separate location in the array, but how is it valid
without being marked as volatile or using AtomicIntegerArray?

public class ForkBlur extends RecursiveAction {
  private int[] mDestination;

  protected void computeDirectly() {
    mDestination[index] = dpixel;

What is the guarantee that at the end of ForkJoinPool.invoke(), the
waiting/submitting thread will be able to see all the changes made to the
array by the various FJ pool threads?

Am I wrong or am I wrong? :)

I had asked a similar question about just writing to a large byte[] but not
about reading it back .. word tearing and such -
http://markmail.org/message/bca7ywwtdjbqbnu3. But in this FJ demo, we are
reading the results at the end.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110805/0bc98b8b/attachment.html>

More information about the Concurrency-interest mailing list