Login  Register

Re: Arrays and thread safety

Posted by Michael Doube on May 08, 2009; 1:50pm
URL: http://imagej.273.s1.nabble.com/Arrays-and-thread-safety-tp3692620p3692627.html

Albert Cardona wrote:
> Michael Doube wrote:
>> So is it enough for each thread to have access to separate arrays
>> within a 2D array (e.g. different values of z for workArray[z][])?  Or
>> does each thread need its own copy of the elements as a completely
>> separate entity?

> Test it. Separate entity entirely works best for me.
> A subrange of an array doesn't prevent resource access contention.

Hmmm. 2D arrays offer no improvement over 1D arrays - I get the same
unpredictable error.  There might be a bug in my indexing or some
contention going on.

I tested with and without multithreading of that particular method and
found negligible speed increase, so it looks I've got something horribly
  wrong or the method is fundamentally unsuited to multithreading.  For
now I've taken it out.

Thanks everyone for your suggestions,

Mike